Found 6705 Articles for Database

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

96 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

522 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

How can I customize value, instead of NULL, of a row by using MySQL IF() function?

Arushi
Updated on 11-Feb-2020 06:18:34

124 Views

Suppose in our ‘Employee’ table we are having NULL as the value of ‘salary’ column for two employees. The data, shown as follows, is itself not meaningful.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 ... Read More

How can I use a SELECT statement as an argument of MySQL IF() function?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:21

554 Views

It is quite possible to use a SELECT statement as the first argument of MySQL IF() function. To make it understand, consider the data as follows from table ‘Students’. mysql> Select * from Students; +----+-----------+-----------+----------+----------------+ | id | Name | Country | Language | Course | +----+-----------+-----------+----------+----------------+ | 1 | Francis | UK | English | Literature | | 2 | Rick | ... Read More

How can I use MySQL IF() function within SELECT statement?

Monica Mona
Updated on 10-Feb-2020 10:40:37

3K+ Views

It is quite possible to use MySQL IF() function within SELECT statement by providing the name of the column along with a condition as the first argument of IF() function. To understand it, consider the following data from table ‘Students’.mysql> Select * from Students; +----+-----------+-----------+----------+----------------+ | id | Name      | Country   | Language | Course         | +----+-----------+-----------+----------+----------------+ | 1  | Francis   | UK        | English  | Literature     | | 2  | Rick      | USA       | English  | History        | ... Read More

How does MySQL IF() function work?

Ankith Reddy
Updated on 20-Jun-2020 13:22:56

157 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

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

Sharon Christine
Updated on 20-Jun-2020 13:23:30

210 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)

How can we combine functions in MySQL?

Chandu yadav
Updated on 10-Feb-2020 10:43:23

580 Views

Combining of functions in MySQL is quite possible by providing a function as the argument of other function. It is also called nesting of functions. To understand it, consider some examples belowmysql> Select UPPER(CONCAT('www.', 'tutorialspoint', '.com'))As Tutorials; +------------------------+ | Tutorials              | +------------------------+ | WWW.TUTORIALSPOINT.COM | +------------------------+ 1 row in set (0.00 sec) mysql> Select LOWER(CONCAT('WWW.', 'TUTORIALSPOINT', '.COM'))As Tutorials; +------------------------+ | Tutorials              | +------------------------+ | www.tutorialspoint.com | +------------------------+ 1 row in set (0.00 sec)The above queries combine UPPER() and LOWER() function with CONCAT() function.Similarly, we can combine more ... Read More

How can we use MySQL POWER() function with the column’s data values?

Samual Sam
Updated on 20-Jun-2020 13:09:17

143 Views

If we want to use POWER() function with column’s data values then the first argument i.e. the base would be the name of the column and the second argument i.e. the exponent would be as specified by us. To understand it considers a table ‘Employee’ having the following records −mysql> Select * from Employee; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul  | 20000  | | 3  | Advik  | 25000  | | 4  | Aarav  | 65000  | | 5  | Ram    | 20000  | ... Read More

In MySQL, how to raise a number to the power of another number?

Govinda Sai
Updated on 20-Jun-2020 13:09:47

343 Views

POWER() function is used to raise a number to the power of another number. POW() is the synonym of POWER() function. In these functions, the first arguments work as the base and the second argument works as the exponent. SyntaxPOWER(M, N)  Here, M is the number which is the base of exponentiation. N is the number which is the exponent of exponentiation.Examplemysql> Select POWER(2,3),POW(2,3); +------------+----------+ | POWER(2,3) | POW(2,3) | +------------+----------+ |          8 |        8 | +------------+----------+ 1 row in set (0.00 sec)

Advertisements