且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP MySQL从一个表中选择ID,从另一个表中选择信息

更新时间:2022-02-13 22:22:27

这就是他们所说的联接表,您应该使用这样的查询:

This is what they call joining tables, you should use a query like this:

SELECT i.ID, i.Name, i.Phone FROM `queuelist` AS q
LEFT JOIN `info` AS i ON (
    q.clientID = i.ID
);

我在上面的查询中使用别名来表示较短的符号(队列列表变为q,信息变为i),然后将联接条件(ON()之间的位)设置为队列列表中的clientID,应与信息表中的ID.

I'm using aliases for shorter notation in the above query (queuelist becomes q and info becomes i) and then set the join condition (the bit between the ON()) to be the clientID from the queuelist table should match the ID in the info table.

另请参见 http://dev.mysql.com/doc/refman/5.0/en/join.html 了解更多详情.

Also see http://dev.mysql.com/doc/refman/5.0/en/join.html for more details.