How to select multiple tables using mysql?
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.
H开发者_StackOverflow社区ere 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"];
}
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'
Here's one way:
SELECT table1.column1, table2.column2
FROM table1, table2, table3
WHERE table1.column1 = table2.column1
AND table1.column1 = table3.column1;
Pretty much a join...
Here's another way:
SELECT column1, column2, column3
FROM table1
UNION
SELECT column1, column2, column3
FROM table2
UNION
SELECT column1, column2, column3
FROM table3;
精彩评论