用php结合3个mysql表[关闭]

Is it possible to combine the following 3 MySQL tables using PHP?

  • Table 1: Columns - userid, username, userpass
  • Table 2: Columns - accountid, accounttype
  • Table 3: Columns - userid, accountid, date, rating

Please note that I am new to mySQL and PHP

Use left join for better result. first table left join second table (condition) left join third table (condition)

To fetch, for example, a result-set of usernames with their account types and ratings you'd use:

SELECT table1.username, table2.accounttype, table3.rating FROM table1
JOIN table3 ON table3.userid = table1.userid
JOIN table2 ON table2.accountid = table3.accountid;

In the future, I recommend listing your tables with descriptive names, and in the order by which they will be joined to acheive the result-set you need.

Hope this helps