Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to join automatically two rows that means that probably you can just create one row without spliting it:</p> <pre><code>file | date | face cyclist.jpg | 04-05-2012 | true </code></pre> <p>Otherwise if you need to keep separate rows, just select all rows in one query:</p> <pre><code>$res = mysql_query("select * from tags where file='cyclist.jpg'"); </code></pre> <p>and then iterate them to fulfil 'merged' record:</p> <pre><code>$res = mysql_query("select * from tags_table where file='cyclist.jpg'"); $mergedRow = array(); while ($row = mysql_fetch_assoc($res)) { foreach ($row as $rowKey =&gt; $rowValue) { if (!array_key_exists($rowKey, $mergedRow)) { $mergedRow[$rowKey] = $rowValue; } } } </code></pre> <p>Edit:</p> <p>As promised here's a sample of joining two rows into one with single query, however I would still recommend <code>$mergedRow</code> approach in PHP to merging them :)</p> <pre><code>CREATE TABLE `files_table` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `tag_type` enum('PARENT','CHILD') NOT NULL DEFAULT 'PARENT', `date` date DEFAULT NULL, `file` varchar(255) NOT NULL DEFAULT '', `face` smallint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; </code></pre> <p>Then you can 'pair' PARENT-CHILDREN sets with:</p> <pre><code>SELECT t1.file, t1.date, t2.face FROM files_table AS t1 JOIN files_table AS t2 ON (t1.file = t2.file) WHERE t1.tag_type = 'PARENT' AND t2.tag_type = 'CHILD' GROUP BY file </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload