Aravindh Joy
Aravindh Joy

Reputation: 1

How to use join clause

SELECT   c.LastName, 
         c.FirstName, 
         i.InvoiceId, 
         i.CustomerId, 
         i.InvoiceDate, 
         i.BillingCity,
         i.total  
FROM     invoices i 
INNER JOIN customers c ON i.CustomerId=c.CustomerId
WHERE BillingCity LIKE 'P%' OR 'S%'

I am trying to find records from the cities that start with P and S. When I run this query, It only returns the cities with P.

Upvotes: 0

Views: 48

Answers (2)

Nayanish Damania
Nayanish Damania

Reputation: 652

Try this:

SELECT   c.LastName, 
         c.FirstName, 
         i.InvoiceId, 
         i.CustomerId, 
         i.InvoiceDate, 
         i.BillingCity,
         i.total  
FROM     invoices i 
INNER JOIN customers c 
    ON i.CustomerId=c.CustomerId
WHERE (i.BillingCity LIKE 'P%' OR i.BillingCity LIKE 'S%')

Upvotes: 0

Andy Lester
Andy Lester

Reputation: 93636

Your WHERE clause is incorrect. You can't say "LIKE this OR that". You need two different LIKE expressions, joined with an OR.

WHERE 
    BillingCity LIKE 'P%'
    OR 
    BillingCity LIKE 'S%' 

Upvotes: 3

Related Questions