Need help with SQL request for Glossary entry aliases

Re: Need help with SQL request for Glossary entry aliases

by Eloy Lafuente (stronk7) -
Number of replies: 0
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi,

if you want to get everything (entries and aliases) as rows, then something like this should work:

SELECT ge.id, 'entry' as type, ge.concept, ge.definition
FROM mdl_glossary_entries ge
WHERE ge.glossaryid = 8
AND ge.approved = 1

UNION

SELECT al.id, 'alias' as type, al.alias AS concept, ge.definition
FROM mdl_glossary_entries ge
JOIN mdl_glossary_alias al ON al.entryid = ge.id
WHERE ge.glossaryid = 8
AND ge.approved = 1

ORDER BY concept ASC

I've added to it a "type" column to be able to differentiate entries and aliases.

Also, note that it won't be suitable to be used in get_record_xxx() calls, because there can be dupe ids so, surely, you will need to use get_recordset_xxx() + looping instead.

And, of course... you will get some definitions repeated, when there are both entries and aliases.

Hope it helps, ciao smile

Average of ratings: Useful (1)