Database Articles

Page 147 of 546

How can SELECT, without reference to any table, be used to calculate expression in MySQL?

Govinda Sai
Govinda Sai
Updated on 22-Jun-2020 169 Views

With the help of following MySQL statement, we can use SELECT to calculate the expression −SELECT expression;The above statement is having no reference to any table. Followings are some examples −mysql> Select 10 DIV 5; +----------+ | 10 DIV 5 | +----------+ |        2 | +----------+ 1 row in set (0.06 sec) mysql> Select 10*5; +------+ | 10*5 | +------+ |   50 | +------+ 1 row in set (0.00 sec) mysql> Set @var1 = 100, @var2 = 200; Query OK, 0 rows affected (0.00 sec) mysql> Select @Var1+@Var2; +-------------+ | @Var1+@Var2 | +-------------+ |         300 | +-------------+ 1 row in set (0.00 sec)

Read More

How can we get the summary output of a column in MySQL result set itself?

Anvi Jain
Anvi Jain
Updated on 22-Jun-2020 693 Views

We can get the summary output of a column in MySQL result set by using the “WITH ROLLUP” modifier. This modifier is used with GROUP BY CLAUSE. It gives the summary output to include extra rows that represent higher-level summary operations.ExampleIn this example, the WITH ROLLUP modifier gave the summary output with total cost value in the extra row.mysql> Select Item_name, SUM(Cost) AS Total_cost from Item_list GROUP BY Item_name WITH ROLLUP; +-----------+------------+ | Item_name | Total_cost | +-----------+------------+ | Notebook  | 45.00      | | Pen       | 31.70      | | Pencilbox | 125.20     | | NULL      | 201.90     | +-----------+------------+ 4 rows in set (0.00 sec)

Read More

How can we get the metadata of triggers?

Sharon Christine
Sharon Christine
Updated on 22-Jun-2020 235 Views

It can be done with the help of the INFORMATION_SCHEMA database. Following statement will give us the metadata of triggers −mysql> Select trigger_schema, trigger_name, action_statement     -> from information_schema.triggers\G *************************** 1. row ***************************   trigger_schema: query     trigger_name: trigger_before_delete_sample action_statement: BEGIN SET @count = if (@count IS NULL, 1, (@count+1)); INSERT INTO sample_rowaffected values (@count); END *************************** 2. row ***************************   trigger_schema: query     trigger_name: before_inser_studentage action_statement: IF NEW.age < 0 THEN SET NEW.age = 0; END IF *************************** 3. row ***************************   trigger_schema: sys     trigger_name: sys_config_insert_set_user action_statement: BEGIN IF @sys.ignore_sys_config_triggers != true AND NEW.set_by ...

Read More

How it is possible to insert a zero or an empty string into a MySQL column which is defined as NOT NULL?

seetha
seetha
Updated on 22-Jun-2020 2K+ Views

Declaring a column ‘NOT NULL’ means that this column would not accept NULL values but zero (0) and an empty string is itself a value. Hence there would be no issue if we want to insert zero or an empty string into a MySQL column which is defined as NOT NULL. Following comparisons of 0 and empty string with NULL would make it clear −mysql> Select 0 IS NULL, 0 IS NOT NULL; +-----------+---------------+ | 0 IS NULL | 0 IS NOT NULL | +-----------+---------------+ |         0 |             1 | ...

Read More

How can we check the current MySQL transaction isolation level?

karthikeya Boyini
karthikeya Boyini
Updated on 22-Jun-2020 3K+ Views

By executing SELECT @@TX_ISOLATION command we can check the current MySQL transaction isolation level.Examplemysql> SELECT @@TX_ISOLATION; +-----------------+ | @@TX_ISOLATION  | +-----------------+ | REPEATABLE-READ | +-----------------+ 1 row in set (0.00 sec)

Read More

What role data type plays when I insert an empty string into a MySQL column which is declared as NOT NULL?

V Jyothi
V Jyothi
Updated on 22-Jun-2020 231 Views

The representation of an empty string in result set depends on data type when we insert an empty string into a MySQL column which is declared as NOT NULL. As we know that on inserting empty string we are providing value to MySQL that has integer representation as INT 0.Now, if that column is having INTEGER data type then MySQL would show 0 in the result set as that empty string has been mapped to zero as an integer.Examplemysql> create table test(id int NOT NULL, Name Varchar(10)); Query OK, 0 rows affected (0.19 sec) mysql> Insert into test(id, name) ...

Read More

How can we use MySQL SELECT without FROM clause?

Sravani S
Sravani S
Updated on 22-Jun-2020 2K+ Views

FROM clause after SELECT shows the references to a table. But if there is no reference to any table then we can use SELECT without the FROM clause. In other words, we can say that SELECT can be used to retrieve rows computed without reference to any table. Consider the following statements −mysql> Select concat_ws(" ","Hello", "World"); +---------------------------------+ | concat_ws(" ","Hello", "World") | +---------------------------------+ | Hello World                     | +---------------------------------+ 1 row in set (0.00 sec) mysql> Set @var1=100; Query OK, 0 rows affected (0.00 sec) mysql> Select @var1; +-------+ | @var1 | +-------+ |   100 | +-------+ 1 row in set (0.00 sec)

Read More

How can I get the output of multiple MySQL tables from a single query?

Vrundesha Joshi
Vrundesha Joshi
Updated on 22-Jun-2020 416 Views

As we know that a query can have multiple MySQL statements followed by a semicolon. Suppose if we want to get the result from multiple tables then consider the following example to get the result set from ‘Student_info’ and ‘Student_detail’ by writing a single query −mysql> Select Name, Address from Student_info; Select Studentid, Address from Student_detail; +---------+------------+ | Name    | Address    | +---------+------------+ | YashPal | Amritsar   | | Gaurav  | Chandigarh | | Raman   | Shimla     | | Ram     | Jhansi     | | Shyam   | Chandigarh | | ...

Read More

What is the use of &lsquo;c&rsquo; option while writing MySQL statements?

Ramu Prasad
Ramu Prasad
Updated on 22-Jun-2020 584 Views

‘\c’ option means ‘clear’ and is used to clear the current input. Suppose if we do not want to execute a command that we are entering, then we can use a clear \c option which clears the current input. For example, the use of \c option can be done as follows −mysql> Select *     -> from\cIn the example above, when we use \c in a statement, MySQL clears the current input and returns back to the MySQL prompt for accepting other statements.

Read More

What would be the result if we perform any kind of arithmetic calculations in MySQL having one of the arguments as NULL?

radhakrishna
radhakrishna
Updated on 22-Jun-2020 158 Views

MySQL always throws NULL as the result of arithmetic calculations in which one of the arguments is NULL. Consider the following example having NULL as an argument with addition, subtraction, multiplication, and division −mysql> Select 10*NULL; +---------+ | 10*NULL | +---------+ |    NULL | +---------+ 1 row in set (0.12 sec) mysql> Select 10+NULL; +---------+ | 10+NULL | +---------+ | NULL | +---------+ 1 row in set (0.00 sec) mysql> Select 10-NULL; +---------+ | 10-NULL | +---------+ |    NULL | +---------+ 1 row in set (0.07 sec) mysql> Select 10/NULL; +---------+ | 10/NULL | +---------+ ...

Read More
Showing 1461–1470 of 5,456 articles
« Prev 1 145 146 147 148 149 546 Next »
Advertisements