4

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.

3 Answers 3

3

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'
1
  • Yes that seems like the ticket, but when I run it I get this error, 'Error Code: 1046 No database selected'
    – Odyss3us
    Sep 8, 2010 at 8:28
3

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'
3
  • @Mark, :) Sometimes impossible answer faster than you. Sep 8, 2010 at 8:00
  • 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.
    – Odyss3us
    Sep 8, 2010 at 8:02
  • @kielie, Explain please that you try to select in this case? And which columns from each table you need to retrieve. Sep 8, 2010 at 8:05
0

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.