tags:

views:

50

answers:

3

Hello. How do i make a mysql query for more tables to check at once? i mean, something like:

$sql = mysql_query("SELECT username FROM table1, table2, table3 WHERE username = '$username'");
$numer = mysql_num_rows($sql);
echo "You have ".$number;

can you do like this?

What i want to do is to show a user all his posts from the whole site..

+3  A: 

In the query you provided, its using a full outer-join. Use union selects instead.

SELECT username FROM table1 WHERE username = '$username'
UNION SELECT username FROM table2 WHERE username = '$username'
UNION SELECT username FROM table3 WHERE username = '$username'
sam munkes
+1  A: 

You could do with a UNION.

Change the Select-Statement in your mysql_query to...

SELECT username FROM table1 WHERE username = '$username'
UNION
SELECT username FROM table2 WHERE username = '$username'
UNION
SELECT username FROM table3 WHERE username = '$username'
Björn
A: 

You can use the SQL union keyword for that. It is used to union the tables and get the desired data out of them.

Sarfraz