Found 4219 Articles for MySQLi

In which conditions, MySQL CASE statement return NULL?

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

984 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

102 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

87 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

253 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

142 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

94 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

How can we set up a MySQL User account by using SQL GRANT statement?

radhakrishna
Updated on 20-Jun-2020 13:16:33

112 Views

We can also add user account by using GRANT SQL command. It can be illustrated by using the following example −ExampleIn this example, we will add user Zara with password zara123 for a particular database,which is named as TUTORIALS.root@host# mysql -u root -p password; Enter password:******* mysql> use mysql; Database changed mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP    -> ON TUTORIALS.*    -> TO 'zara'@'localhost'    -> IDENTIFIED BY 'zara123';The above statements will also create an entry in the MySQL database table called as a user.

How can we set up a MySQL User account by using INSERT INTO statement?

V Jyothi
Updated on 20-Jun-2020 13:19:29

2K+ Views

For adding a new user to MySQL, we just need to add a new entry to the user table in the database mysql. To illustrate it we are using the following example −ExampleThe following program is an example of adding a new user guest with SELECT, INSERT and UPDATE privileges with the password guest123; the SQL query is −root@host# mysql -u root -p Enter password:******* mysql> use mysql; Database changed mysql> INSERT INTO user (host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'guest', PASSWORD('guest123'), 'Y', 'Y’, 'Y'); Query OK, 1 row affected (0.20 sec) mysql> FLUSH PRIVILEGES; Query OK, ... Read More

How can I get the list of columns from a table in the other database than weare currently using IN operator?

mkotla
Updated on 12-Feb-2020 05:24:22

56 Views

It can be done with the SHOW COLUMNS statement. Its Syntax would be as follows:SyntaxSHOW COLUMNS FROM tab_name IN db_nameHere,  tab_name is the name of the table from which we want to see the list of columns.Db_name is the name of the database, in which the table is storedExampleIn the example, we are currently using the database ‘query’ and getting the list of columnsfrom a table named ‘arena’ stored in MySQL ‘database’:mysql> SHOW COLUMNS FROM arena IN mysql\G *************************** 1. row ***************************   Field: id    Type: int(10) unsigned zerofill    Null: NO     Key: PRI Default: NULL Extra ... Read More

How can we update MySQL table after removing a particular string from the values of column?

Arjun Thakur
Updated on 20-Jun-2020 13:22:08

348 Views

We can update MySQL table after removing a particular string from the values of a column by using TRIM() function along with UPDATE clause. Following the example from ‘examination_btech’ table will make it clearer −ExampleSuppose if we want to delete the values ‘(CSE)’, from last, of column ‘Course’ and want to update the table too then it can be done with the help of the following query −mysql> Update examination_btech SET Course = TRIM(Trailing '(CSE)' FROM Course); Query OK, 10 rows affected (0.13 sec) mysql> Select * from examination_btech; +-----------+----------+--------+ | RollNo    | Name     | Course | +-----------+----------+--------+ | 201712001 | Rahul ... Read More

Advertisements