Aryan PrajapatKnowledge Contributor
How to select all even or all odd records in a table in mysql?
How to select all even or all odd records in a table in mysql?
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.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
By checking the remainder of the division by 2. In some SQL versions (e.g., PostgreSQL and My SQL), we use the MOD function, in the others (Microsoft SQL Server and SQLite) – the modulo operator (%). To select all even records using MOD:
SELECT * FROM table_name
WHERE MOD(ID_column, 2) = 0;
POWERED BY
To select all even records using %:
SELECT * FROM table_name
WHERE ID_column % 2 = 0;