Link to home
Start Free TrialLog in
Avatar of likewhoa321
likewhoa321

asked on

Sql joining question

hi im trying to select the companyname and orderdate for customers in madrid or paris.  I also need to include all customers even if they have no orders.  This is what i have so far.

im getting this error

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'where'.
select c.company, o.orderdate, c.city
from customers as c inner join orders as o
where c.city = 'madrid' or c.city = 'paris'

Open in new window

Avatar of Aneesh
Aneesh
Flag of Canada image

select c.company, o.orderdate, c.city
from customers as c inner join orders as o
on  c.city = 'madrid' or c.city = 'paris'
Avatar of likewhoa321
likewhoa321

ASKER

its giving this error

Msg 207, Level 16, State 1, Line 1
Invalid column name 'company'.
you should check and see whether the table customers has the column named 'company'
ASKER CERTIFIED SOLUTION
Avatar of Chris Luttrell
Chris Luttrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you need a LEFT join.
in regards to:
>Invalid column name 'company'.
you need of course to put the correct column name(s)


select c.company, o.orderdate, c.city
from customers as c
left join orders as o
  on o.customer_id = c.customer_id
wher ec.city = 'madrid' or c.city = 'paris'
Why did you give example code that selected a column called "c.company" and then ask why you get an error "Invalid column name 'company'", we don't know what your columns are, you have to supply that fact or change them to the real names if you are making them up for the example.
sorry about that i meant companyname
np, thanks, glad to be of help.