In this tutorial we’ll not use group by but we will group records. In other words we’ll group records not using group by. We should have at least two tables.
TO DOWNLOAD THE SAMPLE LİBRARY DATABASE CLICK
Example 1:
List the student’s all data and count of the book they read.
1 2 3 |
Select students.*, (Select count(*) from borrows where students.studentId = borrows.studentId) as Count from students |
We used, subquery by column in this example.
The solution with group by same example.
1 2 3 4 |
Select students.studentId,name,surname,class,gender,birthdate,point,count(*) as count from borrows,students where students.studentId = borrows.studentId group by students.studentId,name,surname,class,gender,birthdate,point |
We must write all column names that was listed after the group by clause like the example.
We can’t use students.* after group by clause in sql.