Are the two codes below the same ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Are the two codes below the same ?

SELECT * FROM customers WHERE ID BETWEEN 3 AND 7; SELECT ID FROM customers LIMIT 2,5;

16th May 2018, 9:05 AM
STEPHEN PHILLIP OMUNGALA
STEPHEN PHILLIP OMUNGALA - avatar
10 Answers
+ 2
what if the first query is changed to SELECT ID FROM customers WHERE ID BETWEEN 3 AND 7;
16th May 2018, 9:14 AM
STEPHEN PHILLIP OMUNGALA
STEPHEN PHILLIP OMUNGALA - avatar
+ 1
No they are not. The first returns all the columns where ID is between 3 and 7. The secound returns only the ID column.
16th May 2018, 9:13 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
but are they the same?
16th May 2018, 9:22 AM
STEPHEN PHILLIP OMUNGALA
STEPHEN PHILLIP OMUNGALA - avatar
+ 1
Ulisses Cruz you are confusing the limit section its asking values of id 5 rows starting from 3
16th May 2018, 9:27 AM
STEPHEN PHILLIP OMUNGALA
STEPHEN PHILLIP OMUNGALA - avatar
+ 1
They are not same as the I'd data in the table may not be present in ascending order. so both synatax will give you different results.
19th May 2018, 5:42 AM
Ritesh Bharti
Ritesh Bharti - avatar
0
They are not the same! In the first you are asking values of ID from 3 to 7. In the second you are asking values of ID, but only 2 rows starting from 5th row.
16th May 2018, 9:23 AM
Ulisses Cruz
Ulisses Cruz - avatar
0
Not the same. First return all columns from the fourth ,end with the 7th. The second returns the column named ID,from the 3rd,end with the 7th
16th May 2018, 1:17 PM
junius
0
thanks to everyone
16th May 2018, 1:45 PM
STEPHEN PHILLIP OMUNGALA
STEPHEN PHILLIP OMUNGALA - avatar
0
No, the codes posted below are not the same. The difference in the 2 are as follows: Code #1 Would return every/all columns between ID 3 & 7 . Code #2 Would only return the "ID".
7th Aug 2018, 4:27 AM
Douglas M.