Let's say I have a table with a list of young folk (table1). This table is related to a table that lists all their booty calls (table2). A third table lists their booty calls' booty calls (table3). For the purposes of this example the tables are set up as a one to many relationship.
The young folks in table1 want to lower their risk of contracting an STD by kicking their single most sexually active booty call to the curb. So the challenge is to create a query that displays all the young folk in table1 along with who they should kick to the curb. Who they should kick to the curb is based on how many booty calls their booty calls have.
This is where I'm at...
select t1.ID, t2.ID,
(Select Count(t3.ID) from table3 t3 Where t3.Parent_ID = t2.ID) as BootyCalls
From table1 t1
join table2 t2 on t2.Parent_ID = t1.ID
That query displays all the rows from table1, all the rows from table2 and a BootyCall column which displays the count of table2's booty calls. The problem is that I want to display all the young folk in table1 and their single most sexually active booty call from table2.
Any ideas how to accomplish this in a single query? Thanks in advance for any help!
The young folks in table1 want to lower their risk of contracting an STD by kicking their single most sexually active booty call to the curb. So the challenge is to create a query that displays all the young folk in table1 along with who they should kick to the curb. Who they should kick to the curb is based on how many booty calls their booty calls have.
This is where I'm at...
select t1.ID, t2.ID,
(Select Count(t3.ID) from table3 t3 Where t3.Parent_ID = t2.ID) as BootyCalls
From table1 t1
join table2 t2 on t2.Parent_ID = t1.ID
That query displays all the rows from table1, all the rows from table2 and a BootyCall column which displays the count of table2's booty calls. The problem is that I want to display all the young folk in table1 and their single most sexually active booty call from table2.
Any ideas how to accomplish this in a single query? Thanks in advance for any help!
Comment