Php – How to select multiple tables using thesql

MySQLPHP

Okay, so far I can select two tables using mysql but I cant select three or more tables using mysql how can I select more then three tables using mysql.

Here is the code below.

SELECT users.*, oldusers.* FROM users, oldusers WHERE users.user_id='$user_id' = oldusers.user_id

I'm trying to add all the tables contents into something like this.

while($row = mysqli_fetch_array($dbc)){ 
    $first_name = $row["first_name"];
    $last_name = $row["last_name"];

}

Best Answer

I think you're looking to use an INNER JOIN - where you group together tables based on the same column. What's your exact purpose?

SELECT users.*, oldusers.*, anotherTable.*

FROM users

INNER JOIN oldusers ON oldusers.user_id = users.user_id
INNER JOIN anotherTable ON oldusers.user_id = anotherTable.anotherid

WHERE users.user_id = 'something'
// AND anotherTable.foo = 'bar'