Selecting rows where remainder (modulo) is 1 after division by 2?

SqlDatabaseSelectWhere ClauseModulus

Sql Problem Overview


There is a column in options that hold an integer. I want to select the row only if that value % 2 = 1.

I know this can be done in 2 queries but is it possible to do it in 1?

Sql Solutions


Solution 1 - Sql

MySQL, SQL Server, PostgreSQL, SQLite support using the percent sign as the modulus:

WHERE column % 2 = 1

For Oracle, you have to use the MOD function:

WHERE MOD(column, 2) = 1

Solution 2 - Sql

At least some versions of SQL (Oracle, Informix, DB2, ISO Standard) support:

WHERE MOD(value, 2) = 1

MySQL supports '%' as the modulus operator:

WHERE value % 2 = 1

Solution 3 - Sql

Note: Disregard this answer, as I must have misunderstood the question.

select *
  from Table
  where len(ColName) mod 2 = 1

The exact syntax depends on what flavor of SQL you're using.

Solution 4 - Sql

select * from table where value % 2 = 1 works fine in mysql.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCarlosView Question on Stackoverflow
Solution 1 - SqlOMG PoniesView Answer on Stackoverflow
Solution 2 - SqlJonathan LefflerView Answer on Stackoverflow
Solution 3 - SqlDavid R TribbleView Answer on Stackoverflow
Solution 4 - SqleinarmagnusView Answer on Stackoverflow