A
A
Anna Denisova2020-08-06 02:59:03
SQL
Anna Denisova, 2020-08-06 02:59:03

How to rewrite the SQL query correctly so that it does not give an error?

$sql = "SELECT  m.*,pp.*,p.id,p.originalpid,p.added,p.name,p.owner,p.favorite_cover,COUNT(pp.trackid)
            FROM ".nobil_om_playlists." p
         inner join ".nobil_om_playlist_pos." pp on pp.playlistid = p.id
         inner join ".nobil_om_songs." m on m.id = pp.trackid
         WHERE p.id=" . $this->id . "
          group by pp.trackid ORDER BY pp.position ASC, pp.id DESC LIMIT " . $pl_songs_limit;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Shendakov, 2020-08-06
@shindax

Please provide the text of the error. And the final query string ( echo $sql ).

D
d-stream, 2020-08-06
@d-stream

Without thinking: group by and asterisks in the select are not normal. Though mysql type forgives.
Well, then a hundred rows were grouped by pp.track_id - that is, as a result, one row, which has two dozen different pp.position "inside" - and which one and why should sql use as a sorting criterion (order by)?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question