Sharon Christine has Published 461 Answers

MySQL stored procedure to return a column value?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 15:05:27

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

Add values of two columns considering NULL values as zero in MySQL

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 15:00:17

For this, use COALESCE() function from MySQL. Let us first create a table −mysql> create table DemoTable -> ( -> Value1 int, -> Value2 int -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 200); Query OK, ... Read More

How can I get the number of times a specific word appears in a column with MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:59:08

For this, you can use COUNT() function. Let us first create a table −mysql> create table DemoTable    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(100)    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert ... Read More

MySQL query to select top 10 records?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:54:57

To select top 10 records, use LIMIT in MySQL. Let us first create a table −mysql> create table DemoTable -> ( -> PageNumber text -> ); Query OK, 0 rows affected (2.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Page-1'); Query OK, 1 row ... Read More

Converting table from MyISAM to INNODB in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:53:21

For this, use ALTER command. Let us first create a table. The default engine is set as“MYISAM” −mysql> create table DemoTable -> ( -> ClientId int NOT NULL AUTO_INCREMENT, -> ClientName varchar(100), -> ClientAge int, -> ClientCountryName varchar(100), -> isMarried boolean, -> PRIMARY KEY(ClientId) -> )ENGINE=MyISAM; Query OK, 0 rows ... Read More

How to search on a MySQL varchar column using a number?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:50:28

Use INSERT() function from MySQL. It has the following parameters −ParameterDescriptionstrString to be modifiedpositionPosition where to insert str2numberNumber of characters to replacestr2String to insert into strLet us first create a table −mysql> create table DemoTable    -> (    -> Code varchar(100)    -> ); Query OK, 0 rows affected ... Read More

Order by desc except a single value in MySQL

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:49:46

Use ORDER BY and set DESC to order by desc. However, to get all the values except a single value, use the not equal operator.Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(100)    -> ); Query OK, 0 rows affected (0.89 ... Read More

How to search a MySQL table for a specific string?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:31:36

Use equal to operator for an exact match −select *from yourTableName where yourColumnName=yourValue;Let us first create a table −mysql> create table DemoTable -> ( -> FirstName varchar(100), -> LastName varchar(100) -> ); Query OK, 0 rows affected (0.70 secInsert some records in the table using insert command −mysql> insert into ... Read More

How to update multiple rows and left pad values in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:29:56

Use the LPAD() function to left pad values. Let us first create a table −mysql> create table DemoTable    -> (    -> Number int    -> ); Query OK, 0 rows affected (2.26 secInsert some records in the table using insert command −mysql> insert into DemoTable values(857786); Query OK, ... Read More

Find and display duplicate values only once from a column in MySQL

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:21:28

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

Advertisements