mysql select中联表,在SELECT(MYSQL / PHP)中联接2个表

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 dairy22 Texas 4000 smth4

Mike Situation glenn32 Jersey 1000 smth1

...

> table "people":

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

> table "countries"

conID postNum region

-------------------------

Jersey 1000 smth1

NYork 2000 smth2

London 3000 smth3

Texas 4000 smth4

! -> NUM is AUTO INCREMENT primary key, which i dont want it the output if possible.

Thanks for help in advance :))

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值