多表查询
SELECT
a.user_uid_type,
a.user_uid,
c.user_id,
c.user_type
FROM
mytable1 a
JOIN mytable2 b
ON(a.user_uid_type = b.user_type AND a.user_uid = b.user_id)
JOIN mytable3 c
on(b.device_id = c.device_id)
WHERE a.date='20151106' AND b.date='20151106' AND c.date='20151106' SORT BY rand() LIMIT 100000
给列起别名需要加AS
SELECT xxx_id AS id FROM yourtable
多列去重选择
SELECT DISTINCE col1, col2 FROM yourtable
left join 和 left outer join区别
这两个其实是一样的,left join是 left outer join的简称
join和left join的区别
比如有两个表
table1
name age
jack 18
bob 19
kate 12
table 2
age career
18 student
30 doctor
那么table1 LEFT JOIN table2就是
name age career
jack 18 student
bob 19 NULL
kate 12 NULL
如果table1 JOIN table2 就是
name age career
jack 18 student