Return Only a Single Row from Duplicate Rows with MySQL

AmitDiwan
Updated on 02-Jan-2020 05:33:52

1K+ Views

To return only a single row from duplicate rows, use DISTINCT keyword −mysql> create table DemoTable1998 (    Name varchar(20) ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1998 values('Robert'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1998 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1998 values('Robert'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1998 values('David'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1998 values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1998 ... Read More

Convert YYYY-MM-DD to Unix Timestamp in MySQL

AmitDiwan
Updated on 02-Jan-2020 05:32:04

839 Views

To convert date to UNIX timestamp, use UNIX_TIMESTAMP() in MySQL −mysql> create table DemoTable1997 (    DueDate date ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1997 values('2018-10-11'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1997 values('2019-12-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1997 values('2017-01-31'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select * from DemoTable1997;This will produce the following output −+------------+ | DueDate    | +------------+ | 2018-10-11 | | 2019-12-21 | ... Read More

Print Inverse Diamond Pattern in C++

Ayush Gupta
Updated on 02-Jan-2020 05:31:01

414 Views

In this tutorial, we will be discussing a program to print given inverse diamond pattern.For this, we will be provided with the value of N. Our task is to print an inverse the diamond pattern according to the height of 2N-1.Example Live Demo#include using namespace std; //printing the inverse diamond pattern void printDiamond(int n){    cout

Display Distinct Column Name in MySQL

AmitDiwan
Updated on 02-Jan-2020 05:29:29

233 Views

Let us create a table −mysql> create table DemoTable1996 (    ShippingDate datetime,    CustomerName varchar(20) ); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1996 values('2019-12-21 10:45:00', 'Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1996 values('2019-12-21 12:10:00', 'David'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1996 values('2019-12-20 12:10:00', 'Bob'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select * from DemoTable1996;This will produce the following output −+---------------------+--------------+ | ShippingDate        | CustomerName ... Read More

Add 11 Days to Current Date in MySQL

AmitDiwan
Updated on 02-Jan-2020 05:27:36

433 Views

Let us first create a table −mysql> create table DemoTable1994 (    ArrivalDate date ); Query OK, 0 rows affected (5.33 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1994 values('2019-12-18'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable1994 values('2019-12-19'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable1994 values('2019-12-20'); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable1994 values('2019-12-25'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1994 values('2018-12-20'); Query OK, 1 row affected (1.42 sec)Display all records from the table using select statement −mysql> select ... Read More

Print Interesting Pattern in C++

Ayush Gupta
Updated on 02-Jan-2020 05:26:34

276 Views

In this tutorial, we will be discussing a program to print a given interesting pattern.For this, we will be provided with the half-width of the pattern. Our task is to print a similar pattern according to the given width with its left and right portions being mirror images of one another.Example Live Demo#include //printing the given pattern void print_pattern(int n){    int i,j;    //printing the upper half    for (i=1; i

Set Custom Messages for Enum Values in MySQL

AmitDiwan
Updated on 02-Jan-2020 05:25:01

187 Views

Use the if else to set custom messages for enum. Let us first create a table −mysql> create table DemoTable1992 (    ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(20),    isActive ENUM('Y', 'N') ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1992(ClientName, isActive) values('Chris', 'N'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1992(ClientName, isActive) values('Bob', 'N'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1992(ClientName, isActive) values('David', 'Y'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1992(ClientName, isActive) values('Carol', ... Read More

Select From Table Where Value Does Not Exist with MySQL

AmitDiwan
Updated on 02-Jan-2020 05:22:00

861 Views

For this, you can use NOT IN() −mysql> create table DemoTable1991 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(20) ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1991(StudentName) values('Chris'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1991(StudentName) values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1991(StudentName) values('David'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1991(StudentName) values('Sam'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1991(StudentName) values('Mike'); Query OK, 1 row affected (0.11 sec)Display all ... Read More

Print Hut in C++

Ayush Gupta
Updated on 02-Jan-2020 05:20:47

294 Views

In this tutorial, we will be discussing a program to print a Hut pattern.For this, we will be provided with the width of the hut to be printed (say N). Our task is to print a hut structure of the given width using stars and a gate inside the hut using line characters.Example Live Demo#include using namespace std; //printing the given hut structure int print_hut(int n){    int i, j, t;       if (n % 2 == 0) {          n++;       }       for (i = 0; i = n / 5)             || (j >= n / 5 && j < n - n / 5 && i == 0)             || (j == 0 && i >= n / 5)             || (j == t && i > n / 5)             || (i

Select Dates That Are One Week Ahead from Today in MySQL

AmitDiwan
Updated on 02-Jan-2020 05:19:12

349 Views

To get dates that are one week ahead from today, use DATEDIFF. Let us first get the current date −mysql> select curdate(); +------------+ | curdate()  | +------------+ | 2019-12-20 | +------------+ 1 row in set (0.00 sec)We will first create a table −mysql> create table DemoTable1990    (    ShippingDate date    ); Query OK, 0 rows affected (0.99 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1990 values('2019-12-13'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1990 values('2019-12-21'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1990 values('2019-12-20'); Query OK, 1 ... Read More

Advertisements