zxpr.net
当前位置:首页 >> mysql多表查询语句 >>

mysql多表查询语句

一使用SELECT子句进行多表查询 SELECT 字段名 FROM 表1,表2 … WHERE 表1.字段 = 表2.字段 AND 其它查询条件 SELECT a.id,a.name,a.address,a.date,b.math,b.english,b.chinese FROM tb_demo065_tel AS b,tb_demo065 AS a WHERE

select * from (两个表的名字) 应该是这样 SQL我也是初学者啊!呵呵 错了别说我啊!

select stuno,classno from 成绩表 where score>90 or score <60

你这两个表里没有相同的字段,那么如果两个表一起查询的时候出现的记录太多了,你也用不了.如果你想查,那么select * from a a,b b 就行了,但我觉得这应该不是你想要的,你最好把表结构改一下,在b表里加一字段,与a表能关联起来,比如id,select * from a a,b b where a.id=b.id

select * from A left join B on A.pos=B.pos and A.id=B.ownerid你可以试一下

select p.name、s.shenfen_num、t.stu_num、d.driver_numfrom people p inner join shenfen s on p.shenfen_id=s.shenfen_idinner join driver d on d.driver_id=p.driver_idinner join stu t on t.stu_id=p.stu_id

select uf.uid,uf.tel,uf.address from userinfo uf where uf.uid in (select u.uid from user u where u.cityid=1 ) limit 0,10 order by uf.uid; 遍历一遍结果,就可以得到你想要的用户id的数据了

select a.k1 a.n1 b.k1 b.n1 from k1 as a and k2 as b where k1.id = k2.id

1:建议将两张表合成一张表,合并好parentid. 加个key搜索字段,非常方便快捷.2:inner join这是MYSQL多表查询语句.

SELECT A.id,A.title,B.tags FROM news AS A INNER JOIN (SELECT GROUP_CONCAT(B.name) AS tags,newsid FROM tagsdata AS A INNER JOIN tags AS B ON A.tagsid = B.tid GROUP BY newsid) AS B ON A.id=B.newsid;

gtbt.net | 6769.net | qwfc.net | krfs.net | xyjl.net | 网站首页 | 网站地图
All rights reserved Powered by www.zxpr.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com