Sharon Christine has Published 436 Articles

MySQL query to search record with apostrophe?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 11:13:57

369 Views

Let us first create a table −mysql> create table DemoTable -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (2.23 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Sam\''s'); ... Read More

Find out the records of students with more than a specific score in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 10:07:06

90 Views

Set it with WHERE and get the records of students more than a specific score. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(100),    -> StudentScore int    -> ); Query OK, ... Read More

MySQL query to get the count of distinct records in a column

Sharon Christine

Sharon Christine

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

204 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 ... Read More

MySQL query to convert timediff() to seconds?

Sharon Christine

Sharon Christine

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

406 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 ... Read More

How to extract the digit part from the string in MySQL?

Sharon Christine

Sharon Christine

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

2K+ 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 ... Read More

How to select month and year from dates in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 09:49:03

369 Views

To select month and year in MySQL, you can use MONTH() and YEAR() method. Let us first create a table −mysql> create table DemoTable    -> (    -> DueDate datetime    -> ); Query OK, 0 rows affected (0.90 sec)Insert some records in the table using insert command −mysql> ... Read More

Set a certain value first with MySQL ORDER BY?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 09:47:00

1K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Number int    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.13 sec) mysql> insert ... Read More

Fetch middle part of a string surrounded by slash in MySQL

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 09:36:30

331 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Code varchar(100)    -> ); Query OK, 0 rows affected (1.07 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('/101/102/106'); Query OK, 1 row affected (0.14 sec) mysql> insert ... Read More

How to exclude a specific row from a table in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 09:28:04

456 Views

Use i.e. not equal in MySQL to exclude a specific row from a table. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> FirstName varchar(100)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the ... Read More

Selecting and dividing numbers in a column and displaying the decimal result in integer with MySQL

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 09:26:02

437 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> 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 DemoTable(Number) values(10); Query ... Read More

Advertisements