用表名去区别,比如用‘表a.列名’和‘表b.列名’区分开,最好用as重命名,这样查出来的数据才分得清是哪个表出来的,比如‘表a.列名’as ‘a表数据’,‘表b.列名’as ‘b表数据’
SELECT userinfo.id AS uid ,sites.id AS sid,showorder,username,title,ADDTIME FROM sites LEFT JOIN userinfo ON userinfo.id = sites.userid ORDER BY userid DESC LIMIT 0,3;
userinfo和sites两张表有相同的字段'id'; 在查询字段的时候,使用as用别名区分就可以了;
SELECT a.username,b.logintime FROM
(SELECT usercode,username FROM stb1)a
LEFT JOIN
(SELECT usercode,logintime FROM stb2)b
ON
a.usercode=b.usercode
想排序可以在后面加
GROUP BY a.username
select stb1.usercode ,stb1.username,stb2.logintime from stb1,stb2 where stb1.id = stb2.id
是怎样检查的