AmitDiwan has Published 10744 Articles

How to create an empty VIEW in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:58:54

806 Views

To create an empty view in MySQL, following is the syntax −create or replace view yourViewName as select yourValue AS yourColumnName, yourValue AS yourColumnName2, . . N from dual where false;Let us implement the above syntax in order to create an empty view in MySQL −mysql> create or replace view ... Read More

Implementing DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP in MySQL

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:56:30

4K+ Views

With the DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP, a column has the current timestamp for its default value and is automatically updated to the current timestamp.Let us see an example and create a table −mysql> create table DemoTable737 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(100), ... Read More

How to update all the entries except a single value in a particular column using MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:54:03

1K+ Views

To update all the entries while ignoring a single value, you need to use IF().Let us first create a table −mysql> create table DemoTable736 (    CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    CustomerName varchar(100),    isMarried boolean ); Query OK, 0 rows affected (0.53 sec)Insert some records in ... Read More

Delete multiple entries from a MySQL table

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:52:05

798 Views

To delete multiple entries from a MySQL table, use JOIN. Let us first create a table −mysql> create table DemoTabl(Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100)); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName) values('Chris'); Query OK, ... Read More

How to merge rows in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:49:01

5K+ Views

To merge rows in MySQL, use GROUP_CONCAT().Let us first create a table−mysql> create table DemoTable734 (    Id int,    Name varchar(100) ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command−mysql> insert into DemoTable734 values(101, 'John'); Query OK, 1 row affected (0.23 sec) ... Read More

Search records on the basis of date in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:45:58

161 Views

Let us first create a table -mysql> create table DemoTable732 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, PassengerId int, PassengerName varchar(100), PassengerAge int, PassengerTravelDatetime datetime ); Query OK, 0 rows affected (0.67 sec)Insert some ... Read More

Convert string (varchar) to double in MySQL

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:43:51

2K+ Views

Let us first create a table:mysql> create table DemoTable731 (Value varchar(100)); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command -mysql> insert into DemoTable731 values('4.50'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable731 values('7.83'); Query OK, 1 row affected (0.18 sec) ... Read More

Assign an SQL result to variable from prepared statement in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:42:59

2K+ Views

For this, use stored procedure. Let us first create a table −mysql> create table DemoTable(Id int, Name varchar(100)); Query OK, 0 rows affected (1.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 'John'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable ... Read More

MySQL query to count days in date range with start and end date

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:41:11

854 Views

To count days in date range, you need to find the difference between dates using DATEDIFF().Let us first create a table:mysql> create table DemoTable730 (    StartDate date,    EndDate date ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command:mysql> insert into DemoTable730 ... Read More

Display the student marks in a single column on the basis of subject in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:40:10

2K+ Views

For this, use UNION ALL.Let us first create a table:mysql> create table DemoTable729 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(100),    MySQLMarks int,    CMarks int,    JavaMarks int ); Query OK, 0 rows affected (0.40 sec)Insert some records in the table using insert command:mysql> ... Read More

Advertisements