Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>At first you must determine the side which has higher importance - probably artists (might be other way round in another page for example).</p> <p>Your query makes little sense: you're completely missing the <code>JOIN</code> construct. Get your artists and join their songs. You may either use grouping and concatenate all songs for one artist into one field by using <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat" rel="nofollow">GROUP_CONCAT</a> or not group the results and process the set with php (for every track it returns a row with artist name and track name).</p> <p><strong>Grouping by artist:</strong></p> <pre><code>SELECT a.artist_name, GROUP_CONCAT(a.track_name SEPARATOR '; ') AS 'tracks' FROM artists a LEFT JOIN ArtistsTracks at ON at.artist_id = a.artist_id LEFT JOIN Tracks t ON at.track_id = t.track_id GROUP BY a.artist_id </code></pre> <p><strong>EDIT Grouping by track:</strong></p> <pre><code>SELECT a.track_name, GROUP_CONCAT(a.artist_name SEPARATOR '; ') AS 'artists' FROM artists a LEFT JOIN ArtistsTracks at ON at.artist_id = a.artist_id LEFT JOIN Tracks t ON at.track_id = t.track_id GROUP BY a.track_id </code></pre> <p><strong>Plain result:</strong></p> <pre><code>SELECT a.artist_name, a.track_name FROM artists a LEFT JOIN ArtistsTracks at ON at.artist_id = a.artist_id LEFT JOIN Tracks t ON at.track_id = t.track_id </code></pre> <p>Although the first two solutions run generally slower compared to the last one for large data-sets, you must account in the extra processing needed to be done by php for the last solution. Of course, if for example you want to link each track to its own page, you'd be better off with the last one. Just use one, which suits you the most.</p>
    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