MySQL Articles

Page 89 of 355

How MySQL evaluates if I try to add two numbers that are contained in quotes?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 20-Jun-2020 155 Views

If we are trying to add two numbers that are contained in quotes, means we are treating the string as a number. In this case, MySQL converts the value into the closet numeric equivalent and evaluates the result. Following example will demonstrate it.Examplemysql> Select '1525' + '200'As Total; +-------+ | Total | +-------+ | 1725 | +-------+ 1 row in set (0.00 sec)

Read More

How can column data be used within MySQL CASE statement?

Rishi Raj
Rishi Raj
Updated on 20-Jun-2020 234 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 ...

Read More

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

Sravani S
Sravani S
Updated on 20-Jun-2020 164 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 distinguish between MySQL IFNULL() and NULLIF() functions?

karthikeya Boyini
karthikeya Boyini
Updated on 20-Jun-2020 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

In MySQL, without having BOOLEAN data type how can we show TRUE and FALSE values?

Sharon Christine
Sharon Christine
Updated on 20-Jun-2020 255 Views

As we know that there is no BOOLEAN data type in MySQL hence by using TRUE or true, FALSE or false we can enter Boolean values in MySQL statement.Examplemysql> Select TRUE,FALSE; +------+-------+ | TRUE | FALSE | +------+-------+ | 1 | 0 | +------+-------+ 1 row in set (0.00 sec) mysql> Select true,false; +------+-------+ | TRUE | FALSE | +------+-------+ | 1 | 0 | +------+-------+ 1 row in set (0.00 sec)

Read More

How does MySQL IF() function work?

Ankith Reddy
Ankith Reddy
Updated on 20-Jun-2020 201 Views

MySQL IF() function is one of the MySQL control flow functions that returns a value based on a condition. It is sometimes referred to as IF ELSE or IF THEN ELSE function. Basically, it takes three expressions and if the first expression is true (not ZERO and not NULL), it returns the second expression. Otherwise, it returns the third expression. Its syntax is as follows −SyntaxIF(expr, value_if_true, value_if_false)Here expr is the expression having some condition.Value_if_true is the value to return if expr evaluates to TRUE.Value_if_false is the value to return if expr evaluates to FALSE.Examplemysql> Select IF(100=100, 'YES', 'NO'); +------------------------+ ...

Read More

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

Arjun Thakur
Arjun Thakur
Updated on 20-Jun-2020 589 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 ...

Read More

How can I get the list of columns from a table in the other database than we are currently using?

varun
varun
Updated on 20-Jun-2020 143 Views

It can be done with the SHOW COLUMNS statement. Its Syntax would be as follows −SyntaxSHOW COLUMNS FROM db_name.tab_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 columns from table named ‘arena’ stored in mysql ‘database’ −mysql> SHOW COLUMNS FROM mysql.arena\G *************************** 1. row ***************************   Field: id    Type: int(10) unsigned zerofill    Null: NO     Key: PRI Default: NULL   Extra: auto_increment ...

Read More

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

V Jyothi
V Jyothi
Updated on 20-Jun-2020 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 we set up a MySQL User account by using SQL GRANT statement?

radhakrishna
radhakrishna
Updated on 20-Jun-2020 214 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.

Read More
Showing 881–890 of 3,547 articles
« Prev 1 87 88 89 90 91 355 Next »
Advertisements