How To Use The Where & Like Operator Together in SQL?

300 views Asked by At

I want to display a List of Instructors with only first name and last name, from Georgia and whose last name ends in ‘son’.

I have written this so far:

SELECT firstname, lastname, state
FROM instructors
WHERE state = 'ga'
AND lastname LIKE '%son'

But it is not returning the information requested just a blank table.

Any help would be greatly appreciated

4

There are 4 answers

0
BaBar Miamor On BEST ANSWER

FINALLY !!!!!

I Figured It Out!

SELECT firstname, lastname, state
FROM instructors
WHERE state = 'ga'
AND lastname LIKE '*son*'

Instead of using the %WildCard I inserted *WildCard on both ends and it displayed exactly what I was requesting !

Thanks Everyone For Your Help!

0
bowlturner On

To find names ending in 'son' you need to make a small change and remove the second '%' sign. with both it looks for 'son' any where such as 'sonnentag'

The second one I would guess that the DB has Georgia as 'GA' not 'ga'. Case is important.

SELECT firstname, lastname, state
FROM instructors
WHERE state = 'GA'
AND lastname LIKE '*son'
1
Dan Bracuk On

This is a formatted comment that shows you how to troubleshoot. Start with this:

SELECT firstname, lastname, state
FROM instructors
WHERE 1 = 1
-- and state = 'ga'
--AND lastname LIKE '%son'

If that returns no records, you have no data. If it does, uncomment the two other filters, one at a time, to see which one causes no records to be returned. It could well be that you simply have no matching records

1
Phanindra On

This should works to you.

 SELECT [firstname],[Lastname],[state]
 FROM instructors AS i
 WHERE i.state = 'ga' AND i.lastname LIKE '%son'