
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- MySQL query to find all rows where string contains less than four characters?
- MySQL query to find the average of rows with the same ID
- MySQL query to sum rows having repeated corresponding Id
- MySQL query to perform delete operation where id is the biggest?
- MySQL UPDATE query where id is highest AND field is equal to variable?
- How to increment all the rows of a particular column by 1 in a single MySQL query (ID column +1)?
- MySQL query to select rows where column value is only 0, group by another column?
- MySQL query to group concat distinct by Id?
- MySQL query to select distinct order by id
- MySQL query to delete all rows older than 30 days?
- MySQL - How to count all rows per table in one query?
- MongoDB, finding all documents where property id equals to record id?
- MySQL query to find the number of rows in the last query
- MySQL - SUM rows with same ID?
- Find the sum of all 2-digit natural numbers divisible by 4.

Advertisements