SQLTeam.com | Weblogs | Forums

SQL Where Criteron

Hi SqlTeam Forum,

Thanks for taking time out to read this - I've got a SQL script which is currently bringing back circa 4million records. I need to trim this down now by basically adding some SQL code to restrict results.

The data set is basically a list of appointment slots and the desired output is to only pull back results where the 'booked' column is >= 1. So even if Mr Jones, Mortgage Session on the 19th March has 1 client booked in I want all his slots to show. If he has no one booked in I'm not interested in the results (as it's likely it's not filled due to leave or whatever)

Any ideas?

It needs to be where date, person, session are the same and booked new >= 1 then show if date, person, session are the same and booked new = 0 then ignore

A long winded way could be do a basic query to pull back results where booked >= 1 and then join based on person, date, session and bring all results? however I think that would be messy any not sure how I'd go about that :confused:


The exists will probably work for you in this case.