+ 4

What is the mistake in it?

SELECT * FROM Cakes LIMIT 2,ORDER BY calories; It shows there is a mistake near Limit...

31st Oct 2022, 11:51 AM
Riya
Riya - avatar
7 Respostas
+ 5
There should not be comma after 2 Order By should be before limit and also there should be Limit 3
31st Oct 2022, 11:52 AM
A͢J
A͢J - avatar
+ 5
i think you're talking about cakes exercise from SQL course : so you missed one problem statement that it should be ordered ascending... so the working could be like this : SELECT * FROM cakes ORDER BY calories ASC LIMIT 2; it's expected to display 2 rows . you shouldn't get 3 rows The course exercise asks for 3 rows .. SELECT * FROM cakes ORDER BY calories ASC LIMIT 3;
31st Oct 2022, 12:09 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 3
Prashanth Kumar bro since on reading more lesson in SQL ,I understood adding DESC and ASC to ORDER BY ... thank you..
2nd Nov 2022, 5:56 AM
Riya
Riya - avatar
+ 2
A͢J thank you now it works...but why limit is 3 since in SQL it counts from 0..so 2 is enough I thought..but test case failed..
31st Oct 2022, 11:57 AM
Riya
Riya - avatar
+ 2
Prashanth Kumar thank you now I got it...since ORDER BY itself arranges in ascending order by default ..I think ...is it necessary to add ASC to the statement?
31st Oct 2022, 5:17 PM
Riya
Riya - avatar
+ 2
A͢J thank you I confused with index value in lesson ... now I got it
31st Oct 2022, 5:17 PM
Riya
Riya - avatar
+ 1
Riya You need top 3 records that is why Limit 3. Count starts from 1 not 0 here you are not working with index.
31st Oct 2022, 12:51 PM
A͢J
A͢J - avatar