image1=emp_detail (table),
image2=emp_atnd (table),
image3=result that i get right now,
image4 =expected result's image.
这里我有两个表,第一个是 emp_detail 表,第二个是 emp_atnd 表。最后一张图片是我想要的结果,但现在我使用给定查询得到的结果类似于图片 3。
SELECT `emp_id`,`emp_date`,`first_nm` FROM `emp_atnd`,`emp_detail` WHERE `emp_id` IN (SELECT `id` FROM `emp_detail`)AND YEAR(`emp_date`)=2014 LIMIT 0,4
为什么我没有得到我想要的结果?
最佳答案
SELECT emp_id,emp_date,first_nm FROM emp_atnd JOIN emp_details on emp_id = id WHERE YEAR(emp_date)=2014 LIMIT 0,4
关于mysql查询从具有表字段的两个表中获取最后n条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26988869/