Question : Help with MySQL statement

Hi Everyone - I need help with a select statement.  Basically I want to
select * from tablea where id = 'XXXX' however I want to count how many times id='XXXX' appears in tableb in the same SQL statement.  I can't seem to get my head around the syntax.  

Thanks!!

Answer : Help with MySQL statement

Basically it is, that you "shortname" tablenamea -> a1 and a2
select a1.*,  ( select count(a2.id) from tablea a2 where a2.id = 'XXXX') As CountA2
FROM talbea a1
WHERE a1.ID='XXXX';

so in the syntax of matthewspatrick's example:
SELECT a1.civilident, ( SELECT count(a2.tickets from ars2 a2 where a2.tickets = 'XXXX' )
FROM ars2 a1
WHERE a1.civilident = 'XXXX';

The important thing is that you create from your table ars2 two tables that represent ars2 -> a1, a2
From these two references you can now independently query and count, where you otherwise would receive an error.

Hope I could make it clearer.
Random Solutions  
 
programming4us programming4us