Gordon Hughes
asked on
Help with selection query
I am trying to find the records that exist in a table (WOEQLIST0 that do not exist in another table (WOC)
with a sub selection within the table (WOEQLIST)
I have tried
Select WOEQLIST.WONUM, WOEQLIST.EQNUM, WOEQLIST.CLOSEDATE from WOEQLIST, WO, WOC
where WOEQLIST.WONUM = WO.WONUM and WO.CLOSEDATE = '1900-01-01 00:00:00.000' and
WO.REQUESTDATE < '2014-01-01 00:00:00.000' and WOEQLIST.WONUM <> WOC.WONUM
But it does not work, stopped it after bring back 36K
Gordon
with a sub selection within the table (WOEQLIST)
I have tried
Select WOEQLIST.WONUM, WOEQLIST.EQNUM, WOEQLIST.CLOSEDATE from WOEQLIST, WO, WOC
where WOEQLIST.WONUM = WO.WONUM and WO.CLOSEDATE = '1900-01-01 00:00:00.000' and
WO.REQUESTDATE < '2014-01-01 00:00:00.000' and WOEQLIST.WONUM <> WOC.WONUM
But it does not work, stopped it after bring back 36K
Gordon
You are not joining all the tables mentioned in the FROM clause. You have joined WOEQLIST and WO tables but not WOC.
Try this:
OR
I think W2.CLOSEDATE should be W1.CLOSEDATE but I let you decide that.
Select W1.WONUM,
W1.EQNUM,
W1.CLOSEDATE from WOEQLIST W1
LEFT JOIN WOC W2 ON W2.WONUM = W1.WONUM
where W2.CLOSEDATE = '1900-01-01 00:00:00.000'
and
W2.REQUESTDATE < '2014-01-01 00:00:00.000'
and W2 IS NULL
OR
SELECT Select W1.WONUM,
W1.EQNUM,
W1.CLOSEDATE
FROM WOEQLIST W1
WHERE W2.CLOSEDATE = '1900-01-01 00:00:00.000'
and
W2.REQUESTDATE < '2014-01-01 00:00:00.000'
AND NOT EXISTS
(SELECT *
FROM WOC W2
WHERE W1.WONUM = W2.WONUM)
I think W2.CLOSEDATE should be W1.CLOSEDATE but I let you decide that.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works great