在SELECT(MYSQL/PHP)中联接2个表 [英] Joining 2 tables in SELECT(MYSQL/PHP)

查看:78
本文介绍了在SELECT(MYSQL/PHP)中联接2个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这两个表.连接的键"是两个表中都包含的conID. 所以现在我想写选择语句,它会给我这样的东西:

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德克萨斯州4000平方米4

John Smith dairy22 Texas 4000 smth4

迈克情况glenn32球衣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

这篇关于在SELECT(MYSQL/PHP)中联接2个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆