MySQL Query to Get Count of Distinct Records in a Column

Sharon Christine
Updated on 30-Jun-2020 10:04:28

306 Views

To get the count of distinct records, use DISTINCT along with COUNT(). Following is the syntax −select count(DISTINCT yourColumnName) from yourTableName;Let us first create a table −mysql> create table DemoTable -> ( -> Name varchar(20), -> Score int -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 56); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Sam', 89); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('John', 56); Query OK, 1 row affected (0.17 sec) mysql> insert into ... Read More

Convert TIMEDIFF to Seconds in MySQL

Sharon Christine
Updated on 30-Jun-2020 10:01:16

563 Views

For this, you can use TIME_TO_SEC() function. Let us first create a table −mysql> create table DemoTable    -> (    -> SourceTime time,    -> DestinationTime time    -> ); Query OK, 0 rows affected (1.33 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('10:20:00', '4:50:54'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('12:05:10', '7:45:12'); Query OK, 1 row affected (0.30 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+------------+-----------------+ | SourceTime | DestinationTime | +------------+-----------------+ | 10:20:00   ... Read More

Filter Specific Month in MySQL with Varchar Date

karthikeya Boyini
Updated on 30-Jun-2020 09:59:50

435 Views

To filter, you can use STR_TO_DATE() function from MySQL. With that, use MONTH() to get the date from the specific month. Let us first create a table −mysql> create table DemoTable    -> (   -> DueDate varchar(100)    -> ); Query OK, 0 rows affected (1.18 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('06-19-2019'); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable values('01-31-2018'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable values('12-01-2016'); Query OK, 1 row affected (0.14 sec)Display all records from the table using ... Read More

Sort Alphanumeric Column in MySQL

karthikeya Boyini
Updated on 30-Jun-2020 09:58:33

737 Views

To sort an alphanumeric column, use LIKE operator along with SUBSTRING(). Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId varchar(100)    -> ); Query OK, 0 rows affected (1.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('S/TU/100'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('S/TU/1000'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('S/TU/10'); Query OK, 1 row affected (0.47 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following ... Read More

Count Column Values Ignoring NULL in MySQL

karthikeya Boyini
Updated on 30-Jun-2020 09:57:40

165 Views

For this, you can COUNT() method, which does not include NULL value. Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(100),    -> CountryName varchar(100)    -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', null); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Chris', 'US'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Robert', null); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Bob', 'UK'); Query ... Read More

Implement MySQL LIMIT and OFFSET in a Single Query

karthikeya Boyini
Updated on 30-Jun-2020 09:56:32

683 Views

The LIMIT tells about how many records you want while OFFSET gives the records from the given position+1. Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(100)    -> ); Query OK, 0 rows affected (1.33 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 ... Read More

Role of CSS Enabled Selector

seetha
Updated on 30-Jun-2020 09:51:14

218 Views

Use the CSS :enabled selector to style every enabled element. You can try to run the following code to implement the :enabled selector −ExampleLive Demo                    input:enabled {             background: blue;          }                              Subject          Student:          Age:          

Extract Digit Part from String in MySQL

Sharon Christine
Updated on 30-Jun-2020 09:50:34

3K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId varchar(100)    -> ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John19383'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Carol9999'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('David123456'); 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   | +-------------+ | John19383 ... Read More

Style Every p Element with No Children Using CSS

Ankith Reddy
Updated on 30-Jun-2020 09:50:29

964 Views

To style every element that has no children with CSS, use the: empty selector t. You can try to run the following code to implement the: empty selectorExampleLive Demo                    p.demo {             width: 300px;             height: 20px;             background: gray;          }          p:empty {             width: 150px;             height: 20px;             background: orange;          }                     This is demo text. Below is empty text.          

Role of CSS Empty Selector

usharani
Updated on 30-Jun-2020 09:49:59

207 Views

Use the CSS :empty selector to style every element that has no children with CSS. You can try to run the following code to implement the :empty selector −ExampleLive Demo                    p.demo {             width: 300px;             height: 20px;             background: gray;           }           p:empty {              width: 150px;              height: 20px;              background: orange;          }                     This is demo text. Below is empty text.          

Advertisements