Select*fromInformation;+----+---------+|id|Name |+----+ ---------+|1 |Gaurav ||2 |Ram ||3 |Rahul ||4 |Aarav ||5&"/> Select*fromInformation;+----+---------+|id|Name |+----+ ---------+|1 |Gaurav ||2 |Ram ||3 |Rahul ||4 |Aarav ||5&">

Home  >  Article  >  Database  >  How can we get alternate odd records from MySQL table?

How can we get alternate odd records from MySQL table?

WBOY
WBOYforward
2023-08-26 13:33:17583browse

我们如何从 MySQL 表中获取备用奇数记录?

To understand this concept, we are using the data from the table "Information" as follows -

mysql> Select * from Information;
+----+---------+
| id | Name    |
+----+---------+
| 1  | Gaurav  |
| 2  | Ram     |
| 3  | Rahul   |
| 4  | Aarav   |
| 5  | Aryan   |
| 6  | Krishan |
+----+---------+
6 rows in set (0.00 sec)

Now, the following query Alternate odd records will be obtained from the "info" table above -

mysql> Select id,Name from information group by id having mod(id,2) = 1;
+----+--------+
| id | Name   |
+----+--------+
| 1  | Gaurav |
| 3  | Rahul  |
| 5  | Aryan  |
+----+--------+
3 rows in set (0.09 sec)

The above is the detailed content of How can we get alternate odd records from MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete