Limit a single keyword to one column

how to apply a separate keyword in mysql so that it only checks one column field but still returns other columns from my table?

+5
source share
3 answers

In order to do this, mysql needs to know what to do with other columns. You are GROUP In a column that must be unique, and use a function that will tell it what to do with the rest (the so-called aggregate function ). MAX()and COUNT()are typical examples:

SELECT studentId, COUNT(courseId) AS AmountEnrolledCourses
FROM student_enrollment
GROUP BY studentId

SELECT athlete, MAX(distance) AS PersonalRecord
FROM longjump
GROUP BY athlete
+5
source

Instead, you will need to use a group.

SELECT SUM (A), MIN (B), C FROM TABLE, where A> 1 GROUP BY C;

: , - . , , , . . http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html mysql.

+3

SELECT DISTINCT Column_1, Column_2, Column_3 FROM Table

, , , , .

DISTINCT, . ?

-3

All Articles