Query MySQL untuk Menampilkan Nomor Terakhir Pada Tabel Database

Query MySQL untuk Menampilkan Nomor Terakhir Pada Tabel Database




By using order by command we can display the records in the order by marks. By adding the command DESC we can get the records starting from highest to lowest records. So we will get first record of the highest mark and then the second highest mark. We know we can restrict the number of display by using limit command so we will use this limit command to get one record starting from first. So this will return us the second record after the first record. That is if we add the limit command and start from 1 and ask to return 1 record then we will get the second highest mark student. ( not the first or the highest mark ). Here is the sql command to get the second highest mark of class six students.

SELECT * FROM student ORDER BY no DESC LIMIT 1,1;

Limit command will pick up one record staring after the first record so we will get the second highest. If we want to get the first record or the highest mark student then we have to start from 0 record and display one. Like this

SELECT * FROM student ORDER BY no desc LIMIT 0,1;

You can see the only difference between above two SQL commands is the use of starting record mark in limit command. In first case it is 1 and in second case it is set to 0
 Wassalam, Salam Setia IT Central IT Aceh

Bagaimana Dengan Artikel ini....Silahkan Berkomentar Jika ada Pertanyaan Dan Masukan ^_^