Skip to content
Advertisement

SQL subquery , using WHERE & ‘IN’ to filter for specific rows

please use here and copy the code in below to add context to my questions.

As you see, I have a table and within it certain Father’s have the same name, I want to choose the father that has the most dogs for my final list. You can see the entire table in Query #1 , my desired result in Query #2 with respect to Father's returned, but when I am trying to get Father John in Query #3 to only return 1 time but it shows the entire record for Father John with 9 dogs and 10 dogs.

How can I get Query #3 to select only one Father whom has the Max Dogs, and return the rest of the columns as well?

Create tables code:

Query #1

Query #1 OUTPUT:

Query #2

Query #2 OUTPUT

Query #3

Query #3 Output

Desired Output from Query #3

Advertisement

Answer

Try this –

You can also try with row number if your database permits as below-

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement