Victor Sp?ng Arthursson <[EMAIL PROTECTED]> wrote: > > Using mysql version 4.0.x, and would like to know if it is possible to > join in a count(*) from a related table which count the number of > corresponding posts in this per post in the first table? > > A little like: > > table1: > +-------------+----------+ > | id | name | > +-------------+----------+ > | 04002 | victor | > +-------------+----------+ > | 04003 | pierre | > +-------------+----------+ > > table2 > > +-------------+----------+ > | id | relid | > +-------------+----------+ > | 1 | 04002 | > +-------------+----------+ > | 2 | 04002 | > +-------------+----------+ > | 3 | 04002 | > +-------------+----------+ > | 4 | 04003 | > +-------------+----------+ > > The result I want is: > +-------------+----------+ > | id | count(*) | > +-------------+----------+ > | 04002 | 3 | > +-------------+----------+ > | 04003 | 1 | > +-------------+----------+ > > Is this possible? >
Sure. SELECT relid, count(*) from table1, table2 WHERE table1.id=table2.relid GROUP BY relid; -- For technical support contracts, goto https://order.mysql.com/?ref=ensita This email is sponsored by Ensita.net http://www.ensita.net/ __ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Victoria Reznichenko / /|_/ / // /\ \/ /_/ / /__ [EMAIL PROTECTED] /_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.net <___/ www.mysql.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]