MySQL Database Tutorial – 7 – DISTINCT and LIMIT




Facebook – https://www.facebook.com/TheNewBoston-464114846956315/ GitHub – https://github.com/buckyroberts Google+ …

Original source


43 responses to “MySQL Database Tutorial – 7 – DISTINCT and LIMIT”

  1. LIMIT 5 is same as LIMIT 0,5. Which means to start from 'INDEX 0' which is 'ID 1', and retrieve five rows (id 1,2,3,4,5).
    Similarly, 'LIMIT 5,10' means to start from 'INDEX 5' which is 'ID 6', and retrieve 10 rows meaning –> ID 6,7,8,9,10,11,12,13,14,15.
    SIMPLE!

  2. Limit 5 is used because we used 1,2,3,4… As id which was our primary key? What if our id is our primary key but instead of 1,2,3… i used 87FUP as the id? How am i now going to put the limit?

  3. Like your vids, very good way to teach something that's actually pretty simple when you wrap your head around it compared to other aspects of coding. I'd like to point out that limit does not work inherently with Microsoft SQL Server. You need to write the query something like this:

    SELECT TOP 10 property_id, device_id, name FROM device_property ORDER BY property_id DESC

    or like this

    SELECT property_id, device_id, name FROM device_property ORDER BY property_id OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY

  4. i think u should mention the fact that when we write LIMIT 5 (only 1 number) it will show the first 5 ids-names although it starts counting from 0. If it was starting counting from 0, wouldn't it show 6 ids-names(?). 0->1(1ist id) 1->2(2nd id) …… 5(LIMIT)->6(6th id) but that's not what happening

  5. You made a mistake explaining the query with two numbers.
    First number isn't the starting point but the number of rows that will be trimmed from the results (starting from 1, not zero because NULL is ignored, because it seem like you don't have it).
    It does start counting from zero, but in that case, the first displayed number would be 5, not 6.
    Counting with zero: 0, 1, 2, 3, 4 – these would be trimmed and the list would start from 5.

  6. For anyone confused about the numbering of the LIMIT keyword with multiple values, read this:

    Bucky is right when he says that the index count starts at 0. By index count, I mean that the very first row in the column has an index of 0. 

    Where people are getting confused is the fact that the IDs start at 1. Look below for explanation:

    index 0       id 1
    index 1       id 2
    index 2       id 3
    index 3       id 4
    index 4       id 5
    index 5       id 6

    index 14     id 15

    So when you type LIMIT 5, 10  the 5 is referring to the index of 5, meaning it will start by showing id 6. The 10 is referring to how many total rows will be displayed, which is why it only goes up to index of 14 because that's a total of 10 rows if you include the index of 5.

    Hope this helps!

  7. Correct me if I'm wrong but Limit 5,10 should start at 4 if using 0 as the first number, not 6 (0,1, 2, 3, 4 = 5) It appears that LIMIT 5,10 means 10 people after the first 5 IDs (6). If your key started at 100 then LIMIT 5, 10 would start at id 105 (bypassing 100, 101, 102, 103, 104) a small mistake in a great sea of video.

  8. or sudo apt-get install php5-c*rl
    it will look for any package with the latters "php5-crl" it will fill in the missing letters based on what you gave it say you wonna rome all files with the mp3 ext you will run rm *.mp3

Leave a Reply