Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
MySQL Articles
Page 146 of 355
Is it possible to add a set of elements in one cell with MySQL?
To add a set of elements in a single cell, use the concept of JSON. Let us first create a table −mysql> create table DemoTable1828 ( EmployeeId int, EmployeeRecords JSON ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1828 values(1, '[{"EmployeeName":"Chris", "EmployeeAge":29}, {"EmployeeName":"David", "EmployeeAge":27}]'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1828 values(2, '[{"EmployeeName":"John", "EmployeeAge":36}, {"EmployeeName":"Mike", "EmployeeAge":32}]'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1828; This ...
Read MorePerform mathematical operations in a MySQL Stored Procedure?
Let us create a stored procedure. Here, we are calculating amount*quantity i.e. implementing mathematical operations −mysql> delimiter // mysql> create procedure calculation_proc(amount int,quantity int) begin select amount,quantity,(amount*quantity) as Total; end // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;Now you can call a stored procedure using call command −mysql> call calculation_proc(250,3);This will produce the following output −+--------+----------+-------+ | amount | quantity | Total | +--------+----------+-------+ | 250 | 3 | 750 | +--------+----------+-------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)
Read MoreHow to search for ^ character in a MySQL table?
To search for ^ character, use the LIKE operator as in the below syntax −select table_schema, table_name, column_name from information_schema.columns where column_name like '%^%';Let us first create a table −mysql> create table DemoTable1826 ( `^` varchar(20), Name varchar(20), `^Age` int ); Query OK, 0 rows affected (0.00 sec)Here is the query to search for ^ character in a MySQL tablemysql> select table_schema, table_name, column_name from information_schema.columns where column_name like '%^%';This will produce the following output −+--------------+---------------+-------------+ | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | +--------------+---------------+-------------+ | ...
Read MoreDisplay only NOT NULL values from a column with NULL and NOT NULL records in MySQL
For this, you can use IS NOT NULL property. Let us first create a table −mysql> create table DemoTable1 ( DueDate date ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values('2019-09-10'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1 values(NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1 values('2019-11-10'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1; This will produce the following output −+------------+ ...
Read MoreImplement If else in stored procedure in MySQL?
To implement if-else, the syntax is as follows −if yourCondition then yourStatement1; else yourStatement2; end if ;To understand the above concept for if-else in a stored procedure, let us create a stored procedure −mysql> delimiter // mysql> create procedure If_else_stored_demo(value int) begin if value > 1000 then select "your value is greater than 1000"; else select "your value is less than or equal to 1000"; end if ; end // Query OK, 0 rows affected (0.00 ...
Read MoreHow to increase precision with division in MySQL?
To increase precision with division, use MySQL CAST(). Let us first create a table −mysql> create table DemoTable1823 ( Value int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1823 values(1); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1823 values(2); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1823 values(3); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1823;This will produce the following output −+-------+ | Value ...
Read MoreUpdate record on a specific date matching the current date in MySQL
Let us first create a table −mysql> create table DemoTable1822 ( Amount int, DueDate date ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1822 values(1000, '2019-10-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1822 values(500, '2019-11-30'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1822 values(700, '2018-11-30'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1822;This will produce the following output −+--------+------------+ | Amount | ...
Read MoreWill MySQL work if we won’t include the size of VARCHAR while creating a new table?
No, the query won’t work. Let’s create the same scenario and check the error −mysql> create table DemoTable1821 ( Id int, FirstName varchar, LastName varchar ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', LastName varchar )' at line 4To remove the above error, you need to give the size of varchar(10). Let us first create a table −mysql> create table DemoTable1821 ( Id int, ...
Read MoreMySQL query to subtract date records with week day and display the weekday with records
For this, you can use DATE_FORMAT(). Let us first create a table −mysql> create table DemoTable1820 ( AdmissionDate varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1820 values('20/10/2019'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1820 values('19/12/2018'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1820 values('16/04/2017'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1820;This will produce the following output −+---------------+ | AdmissionDate | +---------------+ ...
Read MoreCount the same value of each row in a MySQL column?
To count the same value of each row, use COUNT(*) along with GROUP BY clause. Let us first create a table −mysql> create table DemoTable1818 ( Id int, Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1818 values(10, 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1818 values(11, 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1818 values(11, 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1818 values(12, 'Chris'); Query ...
Read More