在 SELECT(MYSQL/PHP) 中加入 2 个表

2021-12-19 00:00:00 select php mysql

我有这两张桌子.连接密钥"是两个表中都包含的 conID.所以现在我想写一个 select 语句,它会给我这样的东西:

I have these two tables. The connecting "key" is conID which is included in both tables. So now i would like to write select statement which would give me something like this:

John Smith 乳品 22 Texas 4000 smth4

John Smith dairy22 Texas 4000 smth4

Mike Situation glenn32 Jersey 1000 smth1...

Mike Situation glenn32 Jersey 1000 smth1 ...

>表人":

NUM   Name lastName  address    conID
-----------------------------------------
  1    John  Smith     dairy22   Texas
  2    Mike  Situation glenn32   Jersey
  3    Duke  Nukem     haris48   NYork
  4    Queen Lisa      court84   London

>表国家"

conID   postNum   region
-------------------------
Jersey  1000      smth1
NYork   2000      smth2
London  3000      smth3
Texas   4000      smth4

<强>!-> NUM 是 AUTO INCREMENT 主键,如果可能的话,我不希望它是输出.

提前感谢您的帮助:))

Thanks for help in advance :))

推荐答案

这应该返回您想要的行,基于 num 列:

This should return the rows you want, based on the num column:

SELECT Name, lastName, address, people.conID, postNum, region 
FROM people 
JOIN countries 
ON people.conID = countries.conID 
WHERE num=1

相关文章