views:

69

answers:

2

Hi, can u please show me how to query 3 tables using *? thanks

+2  A: 

You need to do a join on the tables in order to get the columns of all of them.

Warning: using * to get all columns is bad practice. You should qualify (name) all the columns you need.

Here is an example:

SELECT * 
FROM table1 t1
INNER JOIN table2 t2
  ON t1.key2 = t2.key2
INNER JOIN table3 t3
  ON t1.key3 = t3.key3
Oded
+1  A: 

One way you probably don't like:

SELECT *
FROM table1, table2, table3

You have to give way more information.

This generates the Cartesian product of all the three tables.

Felix Kling
I'm tempted to upvote, but it feels somewhat immoral.
jdv