UXerUIer
UXerUIer

Reputation: 2338

Grouping a column

I'm trying to group a column in my MYSQL table called "set" and I'm trying to retrieve the lowest page_id of that set.

SELECT * FROM pages WHERE project_id ='$project_id' GROUP BY `set` ORDER BY page_id ASC

How would I go about doing this properly?

Upvotes: 1

Views: 57

Answers (1)

João Silva
João Silva

Reputation: 91359

Use the MIN() aggregate function:

SELECT MIN(page_id) AS lowest_page_id
FROM pages 
WHERE project_id ='$project_id' 
GROUP BY `set`

Upvotes: 3

Related Questions