TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   MySQL & Databases (http://www.talkphp.com/mysql-databases/)
-   -   Dozens of questions which I cannot find. v_v (http://www.talkphp.com/mysql-databases/2150-dozens-questions-i-cannot-find-v_v.html)

Orc 01-31-2008 03:03 AM

Dozens of questions which I cannot find. v_v
 
Heres some questions which I cannot find online, cause it's all about crap PHP Tutorials with MySQL. Now

How would I insert two querys at once? in the same variable:
PHP Code:

$query "SELECT * FROM `table`,
          INSERT INTO `table` (id,name,blah) VALUES(, 'blah', 'blah', 'blah'); 

How would I assign tables/columns/etc to a different column, say I wanted to inherit some columns like so:
PHP Code:

// I want t1's users to be t2's users
$query " SELECT t1.users,t2.users FROM t1,t2
SET `table1` AS `t1` AND `table2` AS `t2`"


How would I edit columns in the tables?
PHP Code:

 $query "TRUNCATE `table` WHERE `blah`='$blah'"

How would I move values from columns to other columns?


That's all the questions I have for now, I might ask some more later.. HALP!

Orc 01-31-2008 03:06 AM

If someone helps me out, they get a cookie! :D

Orc 01-31-2008 03:11 AM

We need a MySQL Guru. -_-

Village Idiot 01-31-2008 03:22 AM

Surely you can wait 10min..... Its 24/7 staff you seem to want.

1. You cant execute more then one query though mysql_query, here some code I wrote that can enable you to do this in a different way http://www.talkphp.com/absolute-begi...l-queries.html


2. I dont get what you are trying to do, why not select both via aliasing?
// I want t1's users to be t2's users
$query = " SELECT t1.users AS t1_users,t2.users AS t2_users FROM t1,t2;


3. Modify an existing MySQL column - Tech-Recipes.com

A quick google serach could have answered the second two

Salathe 01-31-2008 03:32 AM

Quote:

Originally Posted by Orc (Post 10009)
How would I assign tables/columns/etc to a different column, say I wanted to inherit some columns like so:
PHP Code:

// I want t1's users to be t2's users
$query " SELECT t1.users,t2.users FROM t1,t2
SET `table1` AS `t1` AND `table2` AS `t2`"



From your code, it looks like you might be wanting to use something like the following:
SQL Code:
SELECT
    t1.users,
    t2.users
FROM
    table1 AS t1,
    table2 AS t2
;

Please be patient when asking questions; even though some of us are on the forums very often, we're not here to drop everything and respond immediately to new posts. Even if that were the case, it does indeed take a few minutes to draft a post. *!*

Orc 01-31-2008 04:09 AM

Quote:

Originally Posted by Salathe (Post 10014)
From your code, it looks like you might be wanting to use something like the following:
SQL Code:
SELECT
    t1.users,
    t2.users
FROM
    table1 AS t1,
    table2 AS t2
;

Please be patient when asking questions; even though some of us are on the forums very often, we're not here to drop everything and respond immediately to new posts. Even if that were the case, it does indeed take a few minutes to draft a post. *!*

Okay, but thanks for answering one of my questions. :D

Orc 01-31-2008 04:59 AM

I think I figured out that Inner join can be used to combine data from other tables to make one table :D

Orc 01-31-2008 10:58 AM

I'm wondering if I have to use queries for listing rows in a table, and updating, deleting, or inserting into tables. -_- I said I'm a newbie at MySQL. :/

buggabill 01-31-2008 01:10 PM

I believe...if I am wrong, someone correct me, please..to insert data from a SELECT query into another table do something like the following:

SQL Code:
INSERT INTO
    generals (name, rank, serialnum)
SELECT
    name, rank, serialnum
FROM
    allsoldiers
WHERE
    rank="General"
The field names do not have to match, but the data type should.

By editing columns in a table, to what are you referring? Do you wish to change the data type or just the data in a specific column/field?

Orc 01-31-2008 01:12 PM

Quote:

Originally Posted by buggabill (Post 10028)
I believe...if I am wrong, someone correct me, please..to insert data from a SELECT query into another table do something like the following:

SQL Code:
INSERT INTO
    generals (name, rank, serialnum)
SELECT
    name, rank, serialnum
FROM
    allsoldiers
WHERE
    rank="General"
The field names do not have to match, but the data type should.

By editing columns in a table, to what are you referring? Do you wish to change the data type or just the data in a specific column/field?

I was trying to list some news entries, then show a checkbox to delete it or edit it. :/

buggabill 01-31-2008 02:42 PM

Sorry for all the questions, but I have one more. Were you planning on adding or removing a column for each news story? Am I misunderstanding you? Are you actually trying to add or delete rows?

TRUNCATE will clean the table out and leave the structure intact. I don't think that is what you want to do...

To delete a row, here is a small example(assuming you had the id of the story):

SQL Code:
DELETE FROM
    newsstories
WHERE
    id=idofstory

Changing data in a column requires you to do an UPDATE query.

example:
SQL Code:
UPDATE
    stories
SET
    body=bodyofstory
WHERE
    id=idofstory

wGEric 01-31-2008 07:50 PM

Quote:

Originally Posted by Orc (Post 10021)
I think I figured out that Inner join can be used to combine data from other tables to make one table :D

Yes, also LEFT JOIN and RIGHT JOIN. You can also do SELECT queries within other queries (as pointed out by buggabill). There's also UNIONs to do two queries at once.
Code:

SELECT name FROM cia WHERE population > (SELECT population FROM cia WHERE name='United States');
SELECT * FROM t1 UNION SELECT * FROM t2 UNION SELECT * FROM t3;



All times are GMT. The time now is 02:48 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0