If I have a mysql query like:
SELECT * FROM table1 WHERE id IN(1,2,3,4) LIMIT 2
Will mysql return the rows with id 1 and 2 or any 2 random id’s from 1,2,3,4 from the table?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It returns the first two records it finds within in the
IN, but unless you specifyorder bythere is no guarantee on order. The number is fixed (number of matches from yourINclause limited (<=) the number specified inLIMITclause ), order is not. Now generally lets say this is your table “main”This query
returns
because thats how the values are in your table.It returns the order in which the data is stored(in a normal MySQL scenario). With order this becomes
returns