Skip to content

Tag: mysql

How to Sort this MySQL Query

I am trying to insert the ORDER BY in this query to sort the Total column: With the following result: Here’s what I have tried so far but no luck: Answer I think you want: Rationale: the ORDER BY clause should go after all UNION ALL subqueries – so it needs to be outside of the GROUP_CONCAT(), in …

Auto-increment a primary key in MySql

During the creation of tables using mysql on phpmyadmin, I always find an issue when it comes to primary keys and their auto-increments. When I insert lines into my table. The auto_increment works perfectly adding a value of 1 to each primary key on each new line. But when I delete a line for example a line w…

Calculate distance and only get one result for every trail_part_id

What I want to achieve is to get only the closest result for every trail_part_id. However I am stuck, I tried to use GROUP BY trail_part_id, but that did not work either as I got the following error message: SELECT list is not in GROUP BY clause and contains nonaggregated column ‘p.latpoint’ which…