We help IT Professionals succeed at work.

sql 2008  sub query

I was attempting to complete this request:
Display all of the supplier information from the suppliers which are from the same country as Norske Meierier.

This is the code that I typed:

SELECT *
FROM Suppliers
WHERE EXIST (SELECT CompanyName FROM Suppliers WHERE CompanyName = 'Norske Meierier' AND Country = 'Norway')
This is the error message that I am getting
Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure 'Norske'.

What mistake am I making and what would be the correct syntax for this code?
Comment
Watch Question

Commented:
I am not sure why are you using "where exists" to filter the same table you are qerying, most likely you want to use the where exists when you are querying a different table that has a common field or key
i believe the correct syntax would be:
select *
from suppliers
where CompanyName = 'Norske Meierier' AND Country = 'Norway'
Commented:
I forgot, if you want it to be a subquery the syntax is:
SELECT *
FROM Suppliers AS sa
WHERE EXIST (SELECT CompanyName FROM Suppliers AS sb WHERE sa.PrimaryKey = sb.PrimaryKey and CompanyName = 'Norske Meierier' AND Country = 'Norway')
TRY THIS..IT WORKS FINE..

SELECT * FROM Suppliers
WHERE EXISTS (SELECT CompanyName FROM Suppliers
WHERE CompanyName = 'Norske Meierier' AND Country = 'Norway')





Thanks,
Sandeep IVS
Top Expert 2011

Commented:
the error is possibly because you are using EXIST instead of the correct phrases EXISTS...

however even then your query appears to make little sense.

if you know the supplier country is Norway then just display all suppliers from norway
which is what your originl requirement is ....

select * from suppliers as s
where country = 'NORWAY'
order by CompanyName



if you want to generally list suppliers for a supplied company then

SELECT S.*
FROM Suppliers as S
Inner Join (select country from suppliers where companyname='xxxxx') as x
on S.country=x.country
 order by s.companyname