Tuesday, March 23, 2010

Select Column Level Fields from more than one table

0 comments
How many books have been purchased along with their quotations in the month of Jan 2010, in order to aggregated values from different table following is an easy way to do it.

Select count(b.book_id) as "Total Books"
,(Select count(q.id)
from tbl_q_received as "q"
where date_format(b.purchase_date,'%y-%m-d')=date_format(b.purchase_date,'%y-%m-d')) as "Total Quotations"
from tbl_book b
where b.purchase_date between '2010-01-01 00:00:00' and '2010-01-3123:59:59'

0 comments: