Sharon Christine has Published 450 Articles

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

If I truncate a table, should I also add indexes?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:19:51

If you truncate a table, you do not need to add indexes because table is recreated after truncating a table and indexes get added automatically.Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FirstName varchar(20), ... Read More

MySQL query to return a substring after delimiter?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 14:18:32

Use SUBSTRING() to return values after delimiter. Let us first create a table −mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John is good in MySQL, Sam is ... Read More

Selecting data from a MySQL table based on a specific month?

Sharon Christine

Sharon Christine

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

Use the MONTH() method in MySQL to select date based on month. Let us first create a table −mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(10), -> UserPostMessageDate datetime, -> UserLikes int -> ); Query OK, 0 rows affected (0.77 sec)Insert ... Read More

Previous 1 ... 3 4 5 6 7 ... 45 Next
Advertisements