多表联查

比如有三张表,student,teacher , project :

  1. 第一种方法:select * from student,teacher,project where student.id=teacher.sid and student.id=project.sid;

  2. 第二种:select * from student inner join teacher on student.id=teacher.sid inner join project on student.id=project.sid;

 select distinct(msg_id),relation_id,from_user_id,msg_type,from_time,msg_id,audit_state,audit_time,audit_content,machine_id,machine_remark,akey_check_state,bkey_check_state from out_box,in_box,user_machine where from_user_id=3 and out_box.id=in_box.msg_id and out_box.relation_id=user_machine.id;

多表联查并去除重复的字段

SELECT unix_timestamp(now())这是mysql获取当前的时间戳

select a.machine_remark,b.alid_time-(unix_timestamp(now())-b.pass_audit_time) as time,b.alid_time,b.pass_audit_time from user_machine as a,visit_alid_time as b where a.machine_id=b.machine_id and a.user_id=3 and terminal_id=123;

posted @ 2017-01-13 11:10  会奔跑的胖子  阅读(179)  评论(0编辑  收藏  举报