Selecting info from multiple tables for one unique ID with PHP and MySQL

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-03-22T00:19:18Z Indexed on 2010/03/22 0:21 UTC
Read the original article Hit count: 601

Filed under:
|

I'm using PHP and MySQL. Is this the best method to select information about "user_1" from four different tables? I know it works, because I have tried it. But is this the preferred method of selecting information from multiple tables for "user_1"?

$query = "SELECT table_1.username, table_2.city, table_3.state, table_4.country
    FROM table_1
    JOIN table_2
        ON table_1.username=table_2.city
    JOIN table_3
        ON table_1.username=table_3.state
    JOIN table_4
        ON table_1.username=table_4.country
    WHERE table_1.username = 'user_1'";

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql