Hi!

I'm having this main table with references to files in it:

kod:
+-----+-------------+
 |  id  |   filnamn   |
+-----+-------------+
 |168 |v008-12.jpg|
+-----+-------------+

Then I have this table to relate one file to one or several categories:

+-----+--------+------+
 |    id   |   fromid   |   toid   |
+-----+--------+------+
 |    4    |       1       |     2     |
 |  257  |       2       |     2     |
+-----+--------+------+

Which lies in this table for categories:

+----+--------------+
 |  id   |   kategorinamn   |
+----+--------------+
 |   5   |       demonstrations         |
 |   6   |        people           |
+----+--------------+

The following sql:

SELECT DISTINCT
    bilder.id, bilder.filnamn, kategorier.kategorinamn
FROM
    bilder
LEFT JOIN
    relateratabell
ON
    bilder.id = relateratabell.fromid
LEFT JOIN
    kategorier
ON
    relateratabell.toid = kategorier.id
WHERE
    (relateratabell.fromid IS NULL OR relateratabell.fromid IS NOT NULL)
AND
   bilder.stickord LIKE '%basta%' //for example
ORDER BY
    filnamn;

Gives the following result:

+---+-----------+--------------------------+
 |  id  |     filnamn     |           kategorinamn                |
+---+-----------+--------------------------+
 | 166| v007-86.jpg | demonstrations                      |
 | 166| v007-86.jpg | people                       |
 | 167| v008-03.jpg | demonstrations                      |
 | 167| v008-03.jpg | people                      |
+---+-----------+--------------------------+

This is what I expected it to, but I'ld rather get a result as this one:

+---+-----------+--------------------------+
 |  id  |     filnamn     |           kategorinamn                |
+---+-----------+--------------------------+
 | 166| v007-86.jpg | demonstrations, people    |
 | 167| v008-03.jpg | demonstrations, people    |
+---+-----------+--------------------------+

Where the categories have been collected together into the same field, so that I don't get multiple rows for the same file… Is this possible to achieve?

Many many thanks to the one who can give me some input!

Sincerely

Victor

---------------------------------------------------------------------
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



Reply via email to