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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Ok - here's a stumper for me. Easy for you?

Author  Topic 

o9z
Starting Member

23 Posts

Posted - 2011-07-06 : 14:03:38
I have 2 tables

t_user and t_entry

t_user ONLY has 1 field I care about which is "username". t_entry only has 2 fields I care about...."username" and "entered date".

Here is how the data looks in t_entry

username | entered date

bsmith 12/12/2010
bsmith 12/13/2010
bsmith 12/14/2010
cthomas 12/12/2010
cthomas 12/14/2010

Notice cthomas is missing a record foro 12/13/2010. All users in the t_user table should have matching records of everyone else in the table. Since cthomas is missing a record for 12/13/2010, the query would need to return this. So first it needs to look at the t_user table and make sure they reside in the table. Then return the entries that DO NOT exist for that user.

Does that make sense? hard to explain!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-06 : 14:10:32
you mean this?

SELECT p.username,p.entereddate
FROM
(
SELECT u.username,e.entereddate
FROM (SELECT username FROM t_user)u
CROSS JOIN (SELECT DISTINCT entereddate FROM t_entry)e
)p
LEFT JOIN t_entry q
On q.username = p.username
AND q.entereddate=p.entereddate
WHERE q.username IS NULL


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -