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'.
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'
ASKER
its giving this error
Msg 207, Level 16, State 1, Line 1
Invalid column name 'company'.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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'
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.
ASKER
sorry about that i meant companyname
np, thanks, glad to be of help.
from customers as c inner join orders as o
on c.city = 'madrid' or c.city = 'paris'