0% found this document useful (0 votes)
128 views1 page

Subqueries by Kudvenkat

The document contains several SQL queries: 1) Selects all columns from two tables, tblProducts and tblProductSales. 2) Selects specific columns from tblProducts where the id is not in a subquery selecting ids from tblProductSales. 3) Left joins tblProducts and tblProductSales on their id columns and selects columns where the joined id from tblProductSales is null. 4) Selects name and total quantity sold from a subquery grouped by product name from tblProducts. 5) Left joins and groups tblProducts and tblProductSales to select name and total quantity sold grouped by name.

Uploaded by

parashuram n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views1 page

Subqueries by Kudvenkat

The document contains several SQL queries: 1) Selects all columns from two tables, tblProducts and tblProductSales. 2) Selects specific columns from tblProducts where the id is not in a subquery selecting ids from tblProductSales. 3) Left joins tblProducts and tblProductSales on their id columns and selects columns where the joined id from tblProductSales is null. 4) Selects name and total quantity sold from a subquery grouped by product name from tblProducts. 5) Left joins and groups tblProducts and tblProductSales to select name and total quantity sold grouped by name.

Uploaded by

parashuram n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

select * from tblProducts

select * from tblProductSales

select Id,Name, Description from tblProducts


where id not in (select distinct productid from tblProductSales)

select tblproducts.Id,Name, Description from tblProducts


left join tblProductSales
on tblProducts.Id=tblProductSales.ProductId
where tblProductSales.ProductId is null

select Name,(select sum(QuantitySold) from tblProductSales where


ProductId=tblProducts.Id) as totalqtysld
from tblProducts
order by Name

select Name,sum(quantitysold) as qtysld from tblProducts


left join tblProductSales
on tblProducts.id=tblProductSales.ProductId
group by Name
order by Name

You might also like