View Full Version : selecting * from multiple tables??
- |Flash Man| -
February 18th, 2007, 11:48 PM
hey all,
i have a very very simple question i'm having a mind blank...any body know
how to select * from multiple tables??
Cheers :)
bwh2
February 19th, 2007, 12:03 AM
well, that depends on what you're trying to do. what are the structure of the tables?
- |Flash Man| -
February 19th, 2007, 12:08 AM
its just an int(11) with no unique or anything like that
bwh2
February 19th, 2007, 12:16 AM
what i'm trying to determine is if you're trying to JOIN or UNION. you would use a JOIN if the tables are relational and share a common field. for instance:
tbl_users
--------------
user_id (PK)
user_name
tbl_posts
--------------
post_id
post_name
user_id (FK)
^ in this case, you would JOIN the tables based on user_id (primary key in tbl_users, foreign key in tbl_posts).
but you would run a UNION if you had two tables with the same structure and wanted to essentially concatenate the tables:
tbl_posts_old
-------------
post_id
post_name
tbl_posts_new
--------------
post_id
post_name
^ in this case, you would UNION the tables in a SELECT statement, which would produce a result set with everything from both tables (that meets the WHERE statement criteria, if any).
- |Flash Man| -
February 19th, 2007, 12:22 AM
aww ok sorry its union i have
ps thanks for that quick lesson ;) was helpfull
bwh2
February 19th, 2007, 12:27 AM
no problem.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.