Found 4381 Articles for MySQL

What kind of string comparison, case-sensitive or not, can be performed by MySQL?

Vikyath Ram
Updated on 20-Jun-2020 13:46:14

240 Views

MySQL cannot perform a case-sensitive comparison when comparing characters. It can be illustrated with the following example from table ‘Employee’ having the following data −mysql> Select * from Employee; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul  | 20000  | | 3  | Advik  | 25000  | | 4  | Aarav  | 65000  | | 5  | Ram    | 20000  | | 6  | Mohan  | 30000  | | 7  | Aryan  | NULL   | | 8  | Vinay  | NULL   | +----+--------+--------+ 8 rows in set (0.09 sec)The result set of the following query shows that MySQL is not case sensitive when comparing characters.mysql> Select * from Employee WHERE Name IN ('gaurav','RAM'); +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 5  | Ram    | 20000  | +----+--------+--------+ 2 rows in set (0.00 sec)

How MySQL can perform case-sensitive string comparison?

Ankith Reddy
Updated on 17-Feb-2020 06:01:43

667 Views

As we know that MySQL is not case-sensitive while comparing characters but it can be changed i.e. MySQL can perform case-sensitive string comparison if we will use BINARY keyword before the expression. Actually, BINARY keyword instructs MySQL to compare the characters in the string using their underlying ASCII values rather than just their letters. It can be illustrated with the following example from table ‘Employee’ having the following data −mysql> Select * from Employee; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul  | 20000  | | 3 ... Read More

How can we distinguish between MySQL IFNULL() and NULLIF() functions?

karthikeya Boyini
Updated on 20-Jun-2020 13:38:38

3K+ Views

Actually, both MySQL IFNULL() and NULLIF() functions are having an almost same syntax as given below −The syntax of IFNULL()IFNULL(expression1, expression2)The syntax of NULLIF()NULLIF(expression1, expression2)They can be distinguished in the way they return the first argument as result. IFNULL() function will return the first argument as a result if it is not NULL and NULLIF() function will return the first argument as a result if both the arguments are not same.mysql> Select IFNULL('Ram', 'Shyam'); +-----------------------+ | IFNULL('Ram', 'Shyam') | +-----------------------+ | Ram                   | +-----------------------+ 1 row in set (0.00 sec) mysql> Select ... Read More

After connecting to MySQL server how can we select a database fromcommand prompt?

Prabhas
Updated on 20-Jun-2020 13:42:08

162 Views

Once we get connected to the MySQL server, it is required to select a database to work with. This is because there might be more than one database available with the MySQL Server.It is very simple to select a database from the mysql> prompt. We can use SQL command ‘use’ to select a database. To illustrate it we are selecting the database named ‘Tutorials’ in the following example −Example[root@host]# mysql -u root -p Enter password:****** mysql> use TUTORIALS; Database changed mysql>Now, we have selected the TUTORIALS database and all the subsequent operations will be performed on the TUTORIALS database.Read More

In which conditions, MySQL CASE statement return NULL?

Arjun Thakur
Updated on 11-Feb-2020 06:41:17

1K+ Views

As we know that if no comparison or condition is true then CASE statement returns the result specified after ELSE statement. But what if there is no ELSE statement, then in this situation, CASE statement would return NULL. Following is an example to demonstrate it.Examplemysql> Select CASE 100     -> WHEN 150 THEN 'It is matched'     -> WHEN 200 THEN 'It is not matched'     -> END As 'It Returns NULL'; +-----------------+ | It Returns NULL | +-----------------+ | NULL            | +-----------------+ 1 row in set (0.00 sec)The query below, using the data from ... Read More

How can column data be used within MySQL CASE statement?

Rishi Raj
Updated on 20-Jun-2020 13:43:50

165 Views

To understand it consider the data, as follows, from the table ‘Students’ −mysql> Select * from Students; +----+-----------+-----------+----------+----------------+ | id | Name      | Country   | Language | Course         | +----+-----------+-----------+----------+----------------+ | 1  | Francis   | UK        | English  | Literature     | | 2  | Rick      | USA       | English  | History        | | 3  | Correy    | USA       | English  | Computers      | | 4  | Shane     | France    | ... Read More

How can we drop an existing database by using mysqladmin?

seetha
Updated on 20-Jun-2020 13:43:10

165 Views

We would need special privileges to create or to delete a MySQL database. Following is the syntax of dropping a database using mysqladmin binary −Syntax[root@host]# mysqladmin -u root -p drop db_name Enter password:******Here, db_name is the name of the database we want to delete.ExampleFollowing is an example to delete a database named TUTORIALS −[root@host]# mysqladmin -u root -p drop TUTORIALS Enter password:******The above statement will give you a warning and it will confirm if you really want to delete this database or not.Dropping the database is potentially a very bad thing to do. Any data stored in the database will be ... Read More

How does MYSQL control flow function CASE works?

Swarali Sree
Updated on 11-Feb-2020 06:29:36

390 Views

MySQL CASE statement is a flow control function that allows us to build conditions inside a query such as SELECT or WHERE clause. We have two syntaxes of CASE statementSyntax-1CASE val WHEN compare_val1 THEN result1 WHEN compare_val2 THEN result2 . . . Else result ENDHere in this 1st syntax, if the val is equal to compare_val1 then the CASE statement returns result1. If the val is equal to compare_val2 then the CASE statement returns result2 and so on.In case if the val does not match any compare_val then the CASE statement returns the result specified in ELSE clause.Examplemysql> Select CASE 100 ... Read More

How can we create a new database by using mysqladmin?

vanithasree
Updated on 20-Jun-2020 13:40:02

202 Views

We would need special privileges to create or to delete a MySQL database. Following is the syntax for creating a new database using mysqladmin binary −Syntax[root@host]# mysqladmin -u root -p create db_name Enter password:******Here, db_name is the name of the database we want to create.ExampleFollowing is a simple example to create a database called TUTORIALS −[root@host]# mysqladmin -u root -p create TUTORIALS Enter password:******The above query will create a MySQL database called TUTORIALS.

How can we establish MySQL database by using MySQL binary at commandprompt?

Sravani S
Updated on 20-Jun-2020 13:41:12

128 Views

You can establish the MySQL database using the mysql binary at the command prompt. It can be understood with the help of the following example −ExampleWe can use following statements to connect to the MySQL server from the command prompt −[root@host]# mysql -u root -p Enter password:******This will give us the mysql> command prompt where we will be able to execute any SQL command. Following is the result of above command −The following code block shows the result of above code −Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.20 MySQL ... Read More

Advertisements