tags:

views:

27

answers:

3

Hi guys, as the title states, I am trying to query multiple mySQL tables in the same DB simultaneously, here is my query,

SELECT * FROM `database_db`.`one, two, three, four, five, six, seven` WHERE uid='1234567'

I am using mySQL workbench to do the query, but when I run it I get this error

Error Code: 1103
Incorrect table name 'one, two, three, four, five, six, seven'

I know that the problem lies with my query, where I select the tables, I am assuming that I cannot select more than one, or maybe my syntax is incorrect?

Is there another way for me to achieve the same result?

EDIT: Each table is different, each has a different amount of columns, the only thing they have in common is the uid.

For instance, table one has the columns "oneA, oneB, oneC" and table two has the columns "twoA, twoB, twoC, twoD, twoE", and so on and so forth for each table, as you can see they do not have the same amount of columns, and are in no way identical to each other.

Thanx in advance.

+2  A: 

IF table structure is identical for tables: one, two, three ... then you can use UNION

SELECT * FROM one
WHERE uid='1234567'
UNION ALL
SELECT * FROM two
WHERE uid='1234567'
UNION ALL
SELECT * FROM three
WHERE uid='1234567'
....
UNION ALL
SELECT * FROM seven
WHERE uid='1234567'
Michael Pakhantsov
+1 same answer but you were faster. :)
Mark Byers
@Mark, :) Sometimes impossible answer faster than you.
Michael Pakhantsov
The table structure is not identical, each table contains different information pertaining to a specific user, the only thing each table has in common is the uid of the user. I am just trying to get 5 users info from the DB.
@kielie, Explain please that you try to select in this case? And which columns from each table you need to retrieve.
Michael Pakhantsov
@Michael, I have edited my original question.
Thanx for all of your help!
+3  A: 

You probably want to JOIN the tables:

SELECT *
FROM one
JOIN two ON one.uid = two.uid
JOIN three ON one.uid = three.uid
WHERE one.uid='1234567'
Mark Byers
Yes that seems like the ticket, but when I run it I get this error,'Error Code: 1046No database selected'
Nvm, got it to work, thanx!
A: 

Maybe I don't understand the question very well but what about something like this:

SELECT *  
  FROM table_a a, table_b b, table_c c 
 WHERE a.uid = b.uid = c.uid = 12345;
tsurko