Groups | Blog | Home
all groups > sql server (alternate) > july 2003 >

sql server (alternate) : Not clear about this query


babuganesh2000 NO[at]SPAM yahoo.com
7/21/2003 2:11:59 AM
select *From titles

(18 row(s) affected)

Totally 18 records are there in Titles table.

When I query

select title,title_id From titles where title like 'T%' and title_id
like 'M%'

It is returning 2 records.

So,now if I introduce a not in 2 places also it should return 16
records.
Whereas it is returning 14 records. What is the bestway to understand
this.

select title,title_id From titles where title not like 'T%' and
title_id not like 'M%'

Thanks
John Bell
7/21/2003 10:35:21 AM
Hi

You should get 16 records if you use an OR instead of the AND in the where
clause.

NOT ( A AND B )
NOT A OR NOT B

John

[quoted text, click to view]

Ross Presser
7/21/2003 1:54:09 PM
babuganesh2000@yahoo.com (Babu) wrote in
news:bc5c149.0307210111.79fb112c@posting.google.com:

[quoted text, click to view]

Apparently two of your records satisfy one but not both of the LIKE
clauses; therefore they are not included in your latter statement.

.... where title like 'T%' and title_id like 'M%' : 2 records
.... where title not like 'T%' and title_id not like 'M%' : 14 records
.... where not (title like 'T%' and title_id like 'M%): 16 records


--
Ross Presser -- rpresser AT imtek DOT com
"... VB is essentially the modern equivalent of vulgar Latin in 13th
Centurary Europe. Understand it, and you can travel to places you never
AddThis Social Bookmark Button