0

I have two Mysql select queries:

select TTS.SSML, TTS_TAG.SORTID, TTS.VoiceId , TTS_TAG.TAGID FROM TTS 
left join TTS_TAG
on TTS_TAG.TTSID = TTS.TTSID 
where TTS.MID = 15

select max(TTS_TAG.SORTID) as maxsort from TTS_TAG
where TTS_TAG.TAGID = 1

I wish to combine both statements into one select statement, with the aggregate value added as a field in resulting output record?

The second aggregate select statement retrieves the maximum 'sort' for all records with the value 1 - if this second select yielded '3', then my desired record set would be:

# SSML, SORTID, VoiceId, TAGID, maxsort
'ssml data', '1', 'Geraint', '4', '3'
  • Not sure I understand your question, but you can add your second query as a sub select in your first query – Lennart Mar 6 at 19:40
0

Thanks Lennart! A second sub select query within the first worked.

select TTS.SSML, TTS_TAG.SORTID, TTS.VoiceId , TTS_TAG.TAGID, 
(select max(TTS_TAG.SORTID) from TTS_TAG
where TTS_TAG.TAGID = 1) as maxsort
FROM TTS 
left join TTS_TAG
on TTS_TAG.TTSID = TTS.TTSID 
where TTS.MID = 15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.