

- 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
Set a specific value for the first three column values in MySQL?
To set a specific value for only 1st three values, you need to use LIMIT 3. Let us first create a table −
mysql> create table DemoTable1968 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1968(Name) values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1968(Name) values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1968(Name) values('Sam'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1968(Name) values('Mike'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1968(Name) values('Carol'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1968;
This will produce the following output −
+----+-------+ | Id | Name | +----+-------+ | 1 | Chris | | 2 | David | | 3 | Sam | | 4 | Mike | | 5 | Carol | +----+-------+ 5 rows in set (0.00 sec)
Here is the query to set a specific value for the first three column values −
mysql> update DemoTable1968 set Name='Robert' order by Id limit 3; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again:
mysql> select * from DemoTable1968;
This will produce the following output −
+----+--------+ | Id | Name | +----+--------+ | 1 | Robert | | 2 | Robert | | 3 | Robert | | 4 | Mike | | 5 | Carol | +----+--------+ 5 rows in set (0.00 sec)
- Related Questions & Answers
- Place a specific value for NULL values in a MySQL column
- Select a specific value between two column values in MySQL?
- Set ENUM in MySQL for column values
- Fix a specific column value and display random values for rest of the rows in MySQL
- MySQL query to find the average of only first three values from a column with five values
- Swap a specific column value in MySQL
- Getting maximum from a column value and set it for all other values in the same column with MySQL?
- How do I set the default value for a column in MySQL?
- Set value only for NULL values in a MySQL table
- Get multiple count in a single MySQL query for specific column values
- Fetch a specific column value (name) in MySQL
- Set a custom value for NULL or empty values in MySQL
- ORDER BY specific field value first in MySQL
- MySQL CONCAT a specific column value with the corresponding record
- Filter column value by the first character in MySQL
Advertisements