MySQL Forums
Forum List  »  Newbie

Re: Select from matchdata with sub query
Posted by: Phillip Ward
Date: February 06, 2023 08:27AM


I’m trying to find all matchData records for a playerId but also getting the matchId of their first match.

To me, that says two queries, not one.

Whenever you build a query, start by constructing the "rowset" from which you'll read the data (the 'from' and 'join'ing bits), then worry about the data itself (the 'select').

- To get all the records for a given Player, you could get get lots of rows.
- To get their first match, you'll get only one (at most).

Trying to mix these two into a single query will give you major headaches.

Guessing at your table structures (some "create table" statements always help - hint, hint), try these:

select * 
from matchData 
where playerID = ?
order by kickOff 

select matchID 
, min( kickOff ) kickOff 
from matchData 
where playerID = ? 
group by matchID

Regards, Phill W.

Options: ReplyQuote

Written By
January 28, 2023 08:14PM
February 03, 2023 09:08PM
Re: Select from matchdata with sub query
February 06, 2023 08:27AM

Sorry, only registered users may post in this forum.

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.