SQL Server Performance

Basic T-SQL Help

Discussion in 'General Developer Questions' started by adude28, Aug 2, 2003.

  1. adude28 New Member

    Why doesn't this work?

    select (select CustomerID
    from orders o
    inner join [Order Details] od on :confused:rderId = od.OrderId
    inner join Products p on od.ProductId = p.Productid
    where p.ProductName = 'Chocolade') as "Column1",
    (select CustomerID
    from orders o
    inner join [Order Details] od on :confused:rderId = od.OrderId
    inner join Products p on od.ProductId = p.Productid
    where p.ProductName = 'Vegie-spread') as "Column2"


  2. bambola New Member

    to correct your syntax


    select Column1.CustomerID, Column2.CustomerID
    from
    (
    select CustomerID
    from orders o
    inner join [Order Details] od on :confused:rderId = od.OrderId
    inner join Products p on od.ProductId = p.Productid
    where p.ProductName = 'Chocolade'
    ) Column1,
    (
    select CustomerID
    from orders o
    inner join [Order Details] od on :confused:rderId = od.OrderId
    inner join Products p on od.ProductId = p.Productid
    where p.ProductName = 'Vegie-spread'
    ) Column2
    but you can write it in a more simple way


    select CustomerID, p.ProductName
    from orders o
    inner join [Order Details] od on :confused:rderId = od.OrderId
    inner join Products p on od.ProductId = p.Productid
    where p.ProductName IN ('Vegie-spread', 'Chocolade')
    Bambola.

Share This Page