faqts : Computers : Databases : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

11 of 29 people (38%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Imagine 2 tables:t1(id int autoinc)(data:1,2,3...),t2(id int)(1,2,2,1,1...) Need query to get t1.id & count(t2.id)where t1.id=t2.id. t2.id CAN BE NUL!

Feb 13th, 2008 00:22
dman, Richard Mitchell, Pasha Rudy, http://sturly.com


select   t1.id, count(t2.id)
from     t1 left join t2
on       t1.id = t2.id
group by t1.id