I want to know if there is a way to use a user-defined variable in WHERE clause, as in this example:
SELECT id, location, @id := 10 FROM songs WHERE id = @id
This query runs with no errors but doesn’t work as expected.
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.
Not far from what Mike E. proposed, but one statement:
I used similar queries to emulate window functions in MySQL. E.g. Row sampling – just an example of using variables in the same statement