MySQL 5.7 returns all columns of a table based on a single column

I just upgraded to MySQL 5.7 and, unfortunately, for me, some GROUP BY functions disappeared. I wanted to select all the movies from my movies table until movies.id type int is a duplicate. My previous query in MySQL 5.6 was:

 SELECT * FROM movies WHERE movies.title LIKE '%example%' GROUP BY movies.id 

If I had two films with the same identifier, this would display only one film, and not that film and its duplicates.

When I upgraded to MySQL 5.7, GROUP BY gave me errors, and I was told instead to use ORDER BY . However, this request:

 SELECT * FROM movies WHERE movies.title LIKE '%example%' ORDER BY movies.id 

Returns duplicate movies. So, is there a way to filter this out and return only the row if it is not a duplicate?

Edit: For example, if this is my movies table:

 movies ================== | id | title | ================== | 1 | example | ------------------ | 2 | example | ------------------ | 1 | example | ------------------ 

Here is the result of each query:

 Previous query result (with MySQL 5.6) ======= 1 | example 2 | example New query result (with MySQL 5.7 and ORDER BY) ======= 1 | example 1 | example 2 | example 

I want the end result to not contain duplicates (so the result should look like the first result of the query).

Edit 2: I understand that I have abused the way MySQL handled GROUP BY . Unfortunately, I do not have much experience with MySQL and received this answer from StackOverflow. I would just like to return all columns in my table that do not contain duplicate id s.

+2
source share
1 answer

I believe it would be easy to use the distinct keyword

 SELECT distinct movies.* FROM movies WHERE movies.title = 'example' 
0
source

Source: https://habr.com/ru/post/1488978/


All Articles