SQL query to select everything from 1 table and 1 column(same name as in table 1) from another table
SQL query to select everything from 1 table and 1 column(same name as in table 1) from another table I have 3 tables. table1 : Products: ProductId Category Model Price Quantity table2: OrderLines: OrderId ProductId Quantity table3: Orders: OrderId CustomerId (theres also a customer table but it doesnt matter) Now I want to select all the products data from Products table that have ProductId = ProductId in OrderLines table, but get the quantity data (of those same products) from the OrderLines table. Tried all kinds of queries, couldn't find one that works. heres the last thing i kind of tried: SELECT tb1.* ,tb2.[Quantity] FROM [Products] tb1, [OrderLines] tb2 WHERE tb1.[ProductId] IN ( SELECT [ProductId] FROM [OrderLines] WHERE OrderId = @orderId) INNER JOIN [OrderLines] tb2 ON[Products].Quantity = [OrderLines].Quantity"; didn't worked. any suggestions? Thanks a lot. sample data: Orders: OrderId CustomerId 1 2 OrderLines: OrderId ProductId Quantity 1...
