Forum Moderators: open
Just had a question about how to form a SQL query. I have a table that stores support ticket entries. There is an integer field called "parent" which denotes whether the entries are tickets or just messages for a ticket (i.e. parent = -1 denotes a ticket, anything else is a ticket reply for that ID).
I am trying to query the table and count how many entries exist with "parent" = each entry ID where parent = -1. So if I have 20 entries total and 5 with "parent = -1" (tickets) then the 15 remaining entries are ticket replies (3 per ticket).
The query should count the replies (where parent != -1) for each entry "where parent = -1". How would I do this for one single table?
I was thinking of creating a separate table for ticket IDs and just inner join the tables but I'd like to use just one.
Thanks in advance!
--Todd