
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Found 4381 Articles for MySQL

587 Views
For this, use UPDATE and REPLACE() in MySQL. Let us first create a table −mysql> create table DemoTable -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(100), -> StudentCountryName varchar(100) -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName, StudentCountryName) values('John', 'US'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql select *from DemoTable;OutputThis will produce the following output −+-----------+-------------+--------------------+ | StudentId | StudentName | StudentCountryName | +-----------+-------------+--------------------+ | ... Read More

1K+ Views
Let us first create a table −mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+----+ | Id | +----+ | 1 ... Read More

1K+ Views
Let us first create a table −mysql> create table DemoTable -> ( -> StudentId varchar(100) -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('STU#123'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('STU#567'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('STU#98494'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+-----------+ | StudentId | +-----------+ | STU#123 | | STU#567 ... Read More

449 Views
To fetch record by year, use the YEAR() method in MySQL −select *from yourTableName where year(yourColumnName)=yourYearValue;Let us first create a table −mysql> create table DemoTable -> ( -> CustomerName varchar(100), -> ShippingDate datetime -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', '2019-01-21'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('Robert', '2018-02-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David', '2016-04-01'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> ... Read More

2K+ Views
For this, you can use stored procedure. Let us create a table dynamically with two columns i.e. StudentId as int, whereas StudentName as varchar −mysql> DELIMITER $$ mysql> CREATE PROCEDURE creatingDynamicTableDemo(yourTableName VARCHAR(200)) -> BEGIN -> SET @name = yourTableName; -> SET @st = CONCAT(' '> CREATE TABLE IF NOT EXISTS `' , @name, '` ( '> `StudentId` int UNSIGNED NOT NULL AUTO_INCREMENT, '> `StudentName` varchar(20) NOT NULL, '> PRIMARY KEY (`StudentId`) '> ) '> '); -> PREPARE ... Read More

243 Views
To search for an integer value in a varchar filed, you can use CASE statement.Let us first create a table. Consider, we have a list of email-ids −mysql> create table DemoTable -> ( -> Title varchar(100) -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('9John@example.com'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('3Carol@gmail.com'); Query OK, 1 row affected (0.45 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+-------------------+ | Title ... Read More

113 Views
For this, use the COUNT() method. Let us first create a table −mysql> create table DemoTable -> ( -> ProductName varchar(100) -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Product-1'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('Product-2'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Product-3'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Product-3'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('Product-2'); Query OK, 1 row affected ... Read More

977 Views
For this, use ORDER BY MAX(). Let us first create a table −mysql> create table DemoTable -> ( -> Id int, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 'John'); Query OK, 1 row affected (0.51 sec) mysql> insert into DemoTable values(10, 'John'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(20, 'Sam'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(20, 'Sam'); Query OK, 1 row affected (0.11 sec) ... Read More

683 Views
For this, you can use ORDER BY clause. Let us first create a table −mysql> create table DemoTable -> ( -> Num1 int, -> Num2 int -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(60, 249); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(59, 250); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+------+------+ | Num1 | Num2 | +------+------+ | 60 | 249 ... Read More

416 Views
Let us first create a table −mysql> create table DemoTable -> ( -> StudentId varchar(100) -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('STU-090'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('STU-123'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('STU-678'); Query OK, 1 row affected (0.29 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+-----------+ | StudentId | +-----------+ | STU-090 | ... Read More