
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to find all rows where ID is divisible by 4?
Let us first create a table with one of the column as ID −
mysql> create table DemoTable ( ID int, StudentName varchar(10), CountryName varchar(20) ); Query OK, 0 rows affected (0.70 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(0,'David','AUS'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(3,'Chris','UK'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(8,'Carol','US'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(9,'Sam','US'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(12,'Robert','UK'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(10,'Mike','AUS'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+------+-------------+-------------+ | ID | StudentName | CountryName | +------+-------------+-------------+ | 0 | David | AUS | | 3 | Chris | UK | | 8 | Carol | US | | 9 | Sam | US | | 12 | Robert | UK | | 10 | Mike | AUS | +------+-------------+-------------+ 6 rows in set (0.00 sec)
Following is the query to find all rows where ID is divisible by 4 −
mysql> select *from DemoTable where (ID%4)=0;
Output
+------+-------------+-------------+ | ID | StudentName | CountryName | +------+-------------+-------------+ | 0 | David | AUS | | 8 | Carol | US | | 12 | Robert | UK | +------+-------------+-------------+ 3 rows in set (0.30 sec)
- Related Questions & Answers
- MySQL query to find all rows where string contains less than four characters?
- MySQL query to perform delete operation where id is the biggest?
- MySQL query to find the average of rows with the same ID
- MySQL UPDATE query where id is highest AND field is equal to variable?
- MySQL query to select rows where column value is only 0, group by another column?
- MySQL query to sum rows having repeated corresponding Id
- MySQL query to select distinct order by id
- MySQL query to group concat distinct by Id?
- How to increment all the rows of a particular column by 1 in a single MySQL query (ID column +1)?
- MongoDB, finding all documents where property id equals to record id?
- Count rotations divisible by 4 in C++
- Listing all rows by group with MySQL GROUP BY?
- MySQL: selecting rows where a column is null?
- MySQL query to delete all rows older than 30 days?
- Minimum steps to make all the elements of the array divisible by 4 in C++
Advertisements