Arjun Thakur has Published 1109 Articles

MySQL LIKE IN()?

Arjun Thakur

Arjun Thakur

Updated on 30-Jul-2019 22:30:24

1K+ Views

You can implement MySQL Like IN() with the help of Regular Expression (regexp) as well. The syntax is as follows −select *from yourTableName where yourColumName regexp ‘value1|value2|value3……|valueN’;To understand the above logic, you need to create a table. Let us first create a table −mysql> create table INDemo ... Read More

What is the limit of auto_increment (integer) in MySQL?

Arjun Thakur

Arjun Thakur

Updated on 30-Jul-2019 22:30:24

911 Views

The limit of auto_increment integer depends on column data type. Displayed as follows:The data type TINYINT range is 127 The data type UNSIGNED TINYINT range is 255 The data type SMALLINT range is 32767 The data type UNSIGNED SMALLINT range is 65535 The data type MEDIUMINT range is 8388607 The ... Read More

Set user variable from result of query in MySQL?

Arjun Thakur

Arjun Thakur

Updated on 30-Jul-2019 22:30:24

899 Views

To set user variable from result of query in MySQL, you need to move that variable into the assignment.To understand the above concept, let us first create a table. The query to create a table is as follows −mysql> create table UserVariable -> ( ... Read More

MYSQL: Can you pull results that match like 3 out of 4 expressions?

Arjun Thakur

Arjun Thakur

Updated on 30-Jul-2019 22:30:24

44 Views

You can use CASE statement to get the results that match some expressions−SELECT *FROM yourTableName WHERE CASE WHEN yourColumnName1 = yourValue1 THEN 1 ELSE 0 END +    CASE WHEN yourColumnName2 = yourValue2 THEN 1 ELSE 0 END +    CASE WHEN yourColumnName3 = yourValue3 THEN 1 ELSE 0 END ... Read More

What is the best way to display in Terminal a MySQL SELECT returning too many fields?

Arjun Thakur

Arjun Thakur

Updated on 30-Jul-2019 22:30:24

106 Views

To achieve this, you can use the following syntax in MySQL −select *from yourTableName\G;Here, G can be used for vertical purpose. You need to add yourTableName.Let us create a table in order to understand the above syntax. Creating a table with the help of CREATE command.The following is the query ... Read More

How to change collation to utf8_bin in a single line?

Arjun Thakur

Arjun Thakur

Updated on 30-Jul-2019 22:30:24

110 Views

You need to use ALTER command to change collation to utf8_bin. The syntax is as follows:ALTER TABLE yourTableName COLLATE utf8_general_ci;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table CollateDemo    -> (    -> Id int NOT NULL ... Read More

Is there a MySQL command to convert a string to lowercase?

Arjun Thakur

Arjun Thakur

Updated on 30-Jul-2019 22:30:24

8K+ Views

Yes, you can use the LOWER() or LCASE() from MySQL to convert a string to lowercase. Both methods can be used to convert the string into lowercase.Here is the syntax of LOWER() −lower(‘yourStringValue);Or you can use LCASE().The syntax is as follows −lcase(‘yourStringValue);Let us see an example of LOWER(). The query ... Read More

Setup the format of DATETIME to 'DDMM- YYYY HH:MM:SS' with MySQL SELECT?

Arjun Thakur

Arjun Thakur

Updated on 30-Jul-2019 22:30:24

2K+ Views

Whenever you retrieve datetime from a table, the datetime gives ‘YYYY-MM-DD’ format. If you want to change the output, then you need to use in-built date_format() from MySQL.The syntax is as follows −SELECT DATE_FORMAT(yourDatetimeColumnName, yourFormat) as anyVariableName from yourTableName;To understand the above syntax, let us first create a table. The ... Read More

How to select data in MySQL where a field has a minimum value?

Arjun Thakur

Arjun Thakur

Updated on 30-Jul-2019 22:30:24

8K+ Views

To select data where a field has min value, you can use aggregate function min(). The syntax is as follows.SELECT *FROM yourTableName WHERE yourColumnName=(SELECT MIN(yourColumnName) FROM yourTableName);To understand the above syntax, let us create a table. The query to create a table is as follows.mysql> create table MinValueDemo -> ( ... Read More

How to easily 'create table from view' syntax in MySQL?

Arjun Thakur

Arjun Thakur

Updated on 30-Jul-2019 22:30:24

2K+ Views

You can create a table from view using create table select syntax. The syntax is as follows −CREATE TABLE yourTableName AS SELECT yourColumnName1, yourColumnName2, yourColumnName3, ........N from yourViewName;To run the above query, first you need to create a table and after that you need to create a view on that ... Read More

Advertisements