I have one table which stores tags for files. The tags can be of different types. There are many files, each with tags stored for them of different types.
columns: file, tagtype, tags
So let’s say I have two rows for one file:
cyclist.jpg | date | 04-05-2012
cyclist.jpg | face | true
I would like to select into one row, all tags for a file, such that I have a mysql result:
cyclist.jpg 04-05-2012 true
At present I carry out two queries for the above, one for each tagtype. I want to know if I can do some kind of join, with the same table, on the same columns (tags), just based on one shared column (file).
If you want to join automatically two rows that means that probably you can just create one row without spliting it:
Otherwise if you need to keep separate rows, just select all rows in one query:
and then iterate them to fulfil ‘merged’ record:
Edit:
As promised here’s a sample of joining two rows into one with single query, however I would still recommend
$mergedRowapproach in PHP to merging them 🙂Then you can ‘pair’ PARENT-CHILDREN sets with: