Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
matrixrep
Starting Member
30 Posts |
Posted - 2014-04-11 : 13:49:39
|
I have two tables:TABLE 1Store------Employee------Begin----------END 001--------1201----------2014-01-01-----2014-02-01001--------1201----------2014-02-02-----2014-02-05001--------1201----------2014-02-06-----2014-02-08TABLE 2Store------Employee------Begin----------END 001--------1201----------2014-01-01-----2014-02-01001--------1201----------2014-02-02-----2014-02-05001--------1201----------2014-02-06-----2014-02-08001--------1201----------2014-02-09-----0I need a query that will find the difference between the two table in that case the missing row in table 1 from table 2I have a lot of employees and stores.This query can be used in msaccess.Thanks in advance for your cooperation. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-04-11 : 15:24:43
|
[code]select * from Table2EXCEPTselect * from Table1;[/code]This query cannot be used in MSACCESS. I am posting only because you posted it to SQL 2008 forum.In Access, one possible approach is to use a left join. But, from your example, I am not clear what the join conditions should be. Perhaps all the columns? |
|
|
matrixrep
Starting Member
30 Posts |
Posted - 2014-04-11 : 16:08:03
|
Find that did the trick in msaccess too.SELECT K.STORE, K.EMPLOYEE, K.BEGIN, K.ENDFROM (SELECT MIN(tmp.TABLENAME) AS TABLELIST, tmp.STORE, tmp.EMPLOYEE, tmp.BEGIN, tmp.END FROM (SELECT 'TABLE 1' as TABLENAME, A.STORE, A.EMPLOYEE, A.BEGIN, A.END FROM TABLE 1 AS A WHERE A.END="0" UNION ALL SELECT 'TABLE 2' as TABLENAME, B.STORE, B.EMPLOYEE, B.BEGIN, B.END FROM TABLE 2 AS B ) AS tmp GROUP BY tmp.STORE, tmp.EMPLOYEE, tmp.BEGIN, tmp.END) AS KWHERE K.TABLELIST="TABLE 2"; |
|
|
|
|
|
|
|