I have a table with tags. It has column identifiers, tagTypeId and tagName. Each item can have many tags. For each element I want to select the first tags with tagTypeId 1, 2 and 3. I tried to add 3 almost identical left connections inside my query, which worked fine, but it was much slower (for example, 5 seconds with a little data in the tables)
it's something like
select i.*, tag1.name, tag2.name, tag3.name from items i
left join (select t.id, t.tagName as name from tags t where t.tagTypeId=1) tag1 on ...
left join (select t.id, t.tagName as name from tags t where t.tagTypeId=2) tag2 on ...
left join (select t.id, t.tagName as name from tags t where t.tagTypeId=3) tag3 on ...
How can I achieve this better in one connection?
vebbo source
share