General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Grouping, counting and then grouping again
I need to create an SQL query where I want to count the number of children on a table. However, I want to group the select before I do the count in order to avoid repetition of another field. How can I do this?
Example:
Main table: events
child table: order definition
grand child table: parts
An event may have many orders, and an order may have many parts.
I want to select the events, and a count of the orders. However for an order to be valid it must have at least one part. So, I created an INNER JOIN between order and parts and an INNER JOIN between events and orders, and I want a count of orders. However, I need to get only one count for each order, even if it has many parts.
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only