2012-07-11 171 views
0

我有2個表mstEmp每日出勤。現在我想運行一個查詢在另一個查詢中查詢加入兩個表

SELECT 
    mstEmp.empname, 
    dailyattendance.InTime, 
    dailyattendance.OutTime, 
    mstEmp.teamtype 
FROM 
    dailyattendance , 
    mstEmp mstEmp 
where 
    dailyattendance.HolderName IN (
    select mstEmp.empname from mstEmp where mstEmp.teamtype='$chk') 

這裏teamtype匹配和對應的名稱是從mstEmp取出,然後用dailyattendance.HolderName匹配的顯示結果。

+0

請詳細... – 2012-07-11 10:25:32

+2

有什麼問題嗎? – MaVRoSCy 2012-07-11 10:30:05

回答

0

這個怎麼樣::

SELECT 
    mstEmp.empname, 
    dailyattendance.InTime, 
    dailyattendance.OutTime, 
    mstEmp.teamtype 

    FROM dailyattendance inner join mstEmp on (dailyattendance.HolderName = mstEmp.empname) 

    where mstEmp.teamtype='$chk' 
    group by mstEmp.empname 
+0

感謝它的工作.. – Lissa 2012-07-11 10:31:00

+0

@HimaniGahlot:WC :-) – 2012-07-11 10:31:59

+0

現在它返回大量行或相同的數據多次 – Lissa 2012-07-11 10:43:10