Select Date Records Between Two Dates in MySQL

AmitDiwan
Updated on 26-Aug-2019 07:31:39

2K+ Views

To select the date records between two dates, you need to use the BETWEEN keyword. Let us first create a table −mysql> create table DemoTable681(AdmissionDate datetime); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable681 values('2019-01-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable681 values('2019-11-01'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable681 values('2019-12-03'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable681 values('2019-07-03'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable681 values('2019-02-04'); Query OK, 1 row affected (0.34 ... Read More

Order and Return Duplicate Column Values Only Once in MySQL

AmitDiwan
Updated on 26-Aug-2019 07:24:03

170 Views

To return a column value only once in MySQL, let us first see an example and create a table −mysql> create table DemoTable680(Status varchar(100)); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable680 values('Busy'); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable680 values('At Work'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable680 values('Busy'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable680 values('Blocked'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable680 values('Offline'); Query OK, 1 row affected (0.67 sec) ... Read More

Types of Relations

Mahesh Parahar
Updated on 26-Aug-2019 07:22:45

809 Views

The Empty Relation between sets X and Y, or on E, is the empty set ∅The Full Relation between sets X and Y is the set X × YThe Identity Relation on set X is the set { (x, x) | x ∈ X }The Inverse Relation R' of a relation R is defined as − R' = { (b, a) | (a, b) ∈ R }Example − If R = { (1, 2), (2, 3) } then R' will be { (2, 1), (3, 2) }A relation R on set A is called Reflexive if ∀ a ∈ A ... Read More

Order Records and Fetch Using MySQL LIMIT

AmitDiwan
Updated on 26-Aug-2019 07:16:39

139 Views

Let us first create a table −mysql> create table DemoTable679(FirstName varchar(100)); Query OK, 0 rows affected (0.44 sec)Insert some records in the table using insert command −mysql> insert into DemoTable679 values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable679 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable679 values('David'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable679 values('Bob'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable679 values('Mike'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable679 values('Sam'); Query OK, 1 row affected (0.15 sec) mysql> insert ... Read More

Sum of Degrees of Vertices Theorem

Mahesh Parahar
Updated on 26-Aug-2019 07:14:19

731 Views

If G = (V, E) be a non-directed graph with vertices V = {V1, V2, …Vn} thenn ∑ i=1 deg(Vi) = 2|E|Corollary 1If G = (V, E) be a directed graph with vertices V = {V1, V2, …Vn}, thenn ∑ i=1 deg+(Vi) = |E| = n ∑ i=1 deg−(Vi)Corollary 2In any non-directed graph, the number of vertices with Odd degree is Even.Corollary 3In a non-directed graph, if the degree of each vertex is k, thenk|V| = 2|E|Corollary 4In a non-directed graph, if the degree of each vertex is at least k, thenk|V| = 2|E|Corollary 5In a non-directed graph, if the ... Read More

Order By Date Set with Varchar Type in MySQL

AmitDiwan
Updated on 26-Aug-2019 07:13:10

600 Views

For this, use ORDER BY STR_TO_DATE in MySQL as in the below syntax −select *from yourTableName ORDER BY STR_TO_DATE(yourColumnName, '%M %Y') DESC;Let us first create a table −mysql> create table DemoTable678(DueDate varchar(200)); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. We have inserted dates here −mysql> insert into DemoTable678 values('March 2019'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable678 values('November 2018'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable678 values('January 2019'); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> ... Read More

MySQL Order By with Custom Field Value

AmitDiwan
Updated on 26-Aug-2019 07:08:35

489 Views

To set custom field value, use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable677(    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserStatus text ); Query OK, 0 rows affected (1.07 sec)Insert some records in the table using insert command −mysql> insert into DemoTable677(UserStatus) values('BUSY'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable677(UserStatus) values('AT WORK'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable677(UserStatus) values('OFFLINE'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable677(UserStatus) values('BLOCKED'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select ... Read More

Concatenate Column Values with Prefix in MySQL

AmitDiwan
Updated on 26-Aug-2019 07:03:50

621 Views

The CONCAT() method would be used to concatenate “MR” to every string, whereas GROUP_CONCAT() to concatenate some of the column values in a single line.Let us first see an example and create a table −mysql> create table DemoTable799(    UserId int,    UserName varchar(100),    UserAge int ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable799 values(101, 'John', 21); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable799 values(102, 'Chris', 26); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable799 values(101, 'Robert', 23); Query OK, ... Read More

Display Records with Latest ID in a MySQL Table

AmitDiwan
Updated on 26-Aug-2019 06:53:39

262 Views

Let us first create a table −mysql> create table DemoTable676(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Number int ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable676(Number) values(1000); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable676(Number) values(1839); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable676(Number) values(29894); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable676(Number) values(1264); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable676(Number) values(190); Query OK, 1 row affected (0.17 sec) mysql> insert into ... Read More

Rooted and Binary Tree

Mahesh Parahar
Updated on 26-Aug-2019 06:51:32

6K+ Views

Rooted TreeA rooted tree G is a connected acyclic graph with a special node that is called the root of the tree and every edge directly or indirectly originates from the root. An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. If every internal vertex of a rooted tree has not more than m children, it is called an m-ary tree. If every internal vertex of a rooted tree has exactly m children, it is called a full m-ary tree. If m = 2, the rooted tree is called a binary tree.Binary ... Read More

Advertisements