0

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"];

}

2
  • Um - where does the third table come into play? Commented Oct 22, 2009 at 6:48
  • it will be added to the while statement like first name. Commented Oct 22, 2009 at 6:52

2 Answers 2

4

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'
Sign up to request clarification or add additional context in comments.

Comments

1

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;

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.