Jump to content

[SOLVED] Select From


TutorMe

Recommended Posts

If you just want to select from multiple tables, it's as easy as:

 

SELECT something FROM table1, table2

 

But, chances are, that's quite useless.... Let's say you have something like this:

 

table users:

 

id     name    password

 

and then you have another table called friends:

 

user_id   friend_id

 

To get the name of the friend, you could do something like:

 

SELECT f.friend_id, u.name FROM friends as f INNER JOIN users as u ON u.id = f.friend_id WHERE f.user_id = 1

 

That would return the friend IDs and names for the user ID 1.

Link to comment
https://forums.phpfreaks.com/topic/67813-solved-select-from/#findComment-340818
Share on other sites

To: pocobueno: I'm not sure exactly what you mean.  I created each table with the following code:

CREATE TABLE `*Month` (
`username` VARCHAR( 20 ) NOT NULL ,
`month` VARCHAR( 13 ) NOT NULL ,
`day` INT( 2 ) NOT NULL ,
`year` INT( 4 ) NOT NULL
) TYPE = MYISAM ;

*Month being replaced by whichever month's table I was creating.  Is that what you were asking for?

 

To: Corbin:  Each table has identical rows, so I tried the following:

$result = mysql_query("SELECT * FROM January, February, etc... ORDER BY day");

However, it just turned up blank.  I appreciate your replies.  I think I'm overlooking something.

 

Link to comment
https://forums.phpfreaks.com/topic/67813-solved-select-from/#findComment-340824
Share on other sites

Thanks for the link, but I actually need to keep the tables separate, but want to display information from all of them in one table.

 

Here is an example using ORDER BY day, but with a different database: http://tutorme.homeip.net/bdays/index.php.

 

It works.  Keep in mind though, that a. there is not much info there, and b. it is displaying each table in a separate table.

Link to comment
https://forums.phpfreaks.com/topic/67813-solved-select-from/#findComment-340858
Share on other sites

Hmmmm.....

 

You could try something like:

 

SELECT * FROM January, February, March, April....

 

Assuming you had something like

 

January

------------

corbin jan 3 1991

TutorMe jan 15 1985

SomeOne jan 15 1985

 

February

--------------

SomeOneElse feb 1 1920

some1 feb 23 1995

someoneelse feb 25 1990

 

It would return something like:

 

corbin jan 3 1991

TutorMe jan 15 1985

SomeOne jan 15 1985

SomeOneElse feb 1 1920

some1 feb 23 1995

someoneelse feb 25 1990

Link to comment
https://forums.phpfreaks.com/topic/67813-solved-select-from/#findComment-340865
Share on other sites

My bad..... My format was entirely incorrect...

 

When you do SELECT * FROM table1, table2 it selects the columns from table1 and table2, not all of the rows.... bleh... sec

 

 

Edit:

 

Ahhh.... After some thinking, I came up with:

 

SELECT * FROM jan

UNION

SELECT * FROM feb

UNION

SELECT * FROM march

UNION

SELECT.... blah blah blah

Link to comment
https://forums.phpfreaks.com/topic/67813-solved-select-from/#findComment-340916
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.