MySQL Forums
Forum List  »  Newbie

need help with a subquert
Posted by: peter mason
Date: November 19, 2015 04:52AM

i have 2 tables i need to get info from and it must be using a sub query for my course, i am totally lost any direction would be appreciated.

i have a horse table and a entry table

the question i have is
List the horse_id and horse name for each horse that has been placed in the top 3 (i.e. got place 1, 2 or 3) two or more times.

the fields of the 2 tables are as follows:


ENTRY (event_id, horse_id, place)
HORSE (horse_id, name, colour, sire, dam, born, died, gender)

i wrote:

use horsedb;
select horse_id, name, sum(if(place<=3,1,0)) as top_3_count
from horse
join entry using (horse_id)
group by horse_id
having top_3_count > 1;

but it got returned for not using a subquery

Options: ReplyQuote


Subject
Written By
Posted
need help with a subquert
November 19, 2015 04:52AM
November 26, 2015 10:06PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.