Finding the 3 smallest numbers in a column

user1282637

I have a table like this:

| songtitle  | songlength  | 
|------------|-------------|
| 1          |      3:42   |
| 2          |      1:32   |
| 3          |      2:44   |
| 4          |      5:00   |
| 5          |      1:19   |
| 6          |      2:54   |

And I want to get the 3 shortest songs (sorted shortest to longest).

I figure I will need something like LIMIT but I'm not positive. Thanks

Barranka

Sort the data and limit the number of rows you want to retreive:

select *
from your_table
order by songlength
limit 3;

If you'd like to get the 3 longest songs, simply order the data in descending order:

select *
from your_table
order by songlength desc
limit 3;

Addressing Dwza's comment, quoting from MySQL Reference Manual:

Columns selected for output can be referred to in ORDER BY and GROUP BY clauses using column names, column aliases, or column positions. [...] To sort in reverse order, add the DESC (descending) keyword to the name of the column in the ORDER BY clause that you are sorting by. The default is ascending order; this can be specified explicitly using the ASC keyword.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Recursion for finding the smallest path of numbers in an array

From Dev

Finding smallest delta available for permutations of a set of numbers

From Dev

Java - Finding Largest and Smallest Numbers using an Array

From Dev

Java - Finding Largest and Smallest Numbers using an Array

From Dev

Finding the 5 smallest numbers from a list in Python

From Dev

Negative numbers not considered when finding smallest number in an array

From Dev

Algorithm for finding the smallest index difference of equal numbers in array

From Dev

Finding largest numbers that go into target leaving smallest remainder

From Dev

finding the minimum between 3 numbers

From Dev

Find the smallest numbers in the second column corresponding to index values in first column

From Dev

finding smallest and second smallest number

From Dev

Finding data change in a column of numbers with pandas

From Dev

Finding data change in a column of numbers with pandas

From Dev

Getting smallest value from column that holds numbers as strings

From Dev

Finding smallest prime factor

From Dev

Finding the smallest integer

From Dev

finding smallest value in PostgreSQL

From Dev

Finding smallest multiple in ruby

From Dev

Better solution for finding numbers with exactly 3 divisors

From Dev

Finding the smallest and second smallest value in an array Java

From Dev

Finding the 3 largest numbers in an array/list of n numbers without the sorting

From Dev

Finding any text in a column - Then moving other numbers beside the found text

From Dev

Finding a sum of numbers from a column in text file python

From Dev

Finding smallest value in generic ArrayList

From Dev

Finding that which sums to the smallest value

From Dev

Finding the k smallest odd integer

From Dev

Finding Second Smallest Element in Array

From Dev

Finding the second smallest integer in array

From Dev

Finding eigenvector corresponding to smallest eigenvalue

Related Related

  1. 1

    Recursion for finding the smallest path of numbers in an array

  2. 2

    Finding smallest delta available for permutations of a set of numbers

  3. 3

    Java - Finding Largest and Smallest Numbers using an Array

  4. 4

    Java - Finding Largest and Smallest Numbers using an Array

  5. 5

    Finding the 5 smallest numbers from a list in Python

  6. 6

    Negative numbers not considered when finding smallest number in an array

  7. 7

    Algorithm for finding the smallest index difference of equal numbers in array

  8. 8

    Finding largest numbers that go into target leaving smallest remainder

  9. 9

    finding the minimum between 3 numbers

  10. 10

    Find the smallest numbers in the second column corresponding to index values in first column

  11. 11

    finding smallest and second smallest number

  12. 12

    Finding data change in a column of numbers with pandas

  13. 13

    Finding data change in a column of numbers with pandas

  14. 14

    Getting smallest value from column that holds numbers as strings

  15. 15

    Finding smallest prime factor

  16. 16

    Finding the smallest integer

  17. 17

    finding smallest value in PostgreSQL

  18. 18

    Finding smallest multiple in ruby

  19. 19

    Better solution for finding numbers with exactly 3 divisors

  20. 20

    Finding the smallest and second smallest value in an array Java

  21. 21

    Finding the 3 largest numbers in an array/list of n numbers without the sorting

  22. 22

    Finding any text in a column - Then moving other numbers beside the found text

  23. 23

    Finding a sum of numbers from a column in text file python

  24. 24

    Finding smallest value in generic ArrayList

  25. 25

    Finding that which sums to the smallest value

  26. 26

    Finding the k smallest odd integer

  27. 27

    Finding Second Smallest Element in Array

  28. 28

    Finding the second smallest integer in array

  29. 29

    Finding eigenvector corresponding to smallest eigenvalue

HotTag

Archive