General discussion

Locked

Select Statements with Condition

By erakana ·
I need some help in the SQL select statements with the condition. The select should contain something like this where:-

One cust_id have many listing_id. Each listing carry status such as O and R. There are thousand's of cust_id with the status of 'O' and 'R'. If the cust_id have all 'O' status and no 'R' status, the another table will be updated.. If have 'O' and 'R' in that cust_id it will be skipped.

What I need to do is to select cust_id that have all listing_id with the status of 'O' only and update in the another table.

Do anyone have suggestions. Pls let me know...
Thank You...

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Tony Hopkinson In reply to Select Statements with Co ...

Lots of ways to do this but my first choice would be

Select cust_id from Customers
Where status = 'O'
DIFFERENCE
Select cust_id from Customers
Where status = 'R'

Put an index on cust_id if you haven't already got one.
Difference is n't used often it goes with
UNION which is all those in either, and INTERSECT which is only those in both.

Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums