MySQLi Articles

Page 61 of 341

How to use MySQL DISTINCT clause on multiple columns?

usharani
usharani
Updated on 22-Jun-2020 6K+ Views

We can use the DISTINCT clause on more than columns in MySQL. In this case, the uniqueness of rows in the result set would depend on the combination of all columns.ExampleConsider the following table ‘testing’ having 10 rows −mysql> select * from testing; +------+---------+---------+ | id   | fname   | Lname   | +------+---------+---------+ |  200 | Raman   | Kumar   | |  201 | Sahil   | Bhalla  | |  202 | Gaurav  | NULL    | |  203 | Aarav   | NULL    | |  204 | Harshit | Khurana | |  205 | Rahul ...

Read More

How Can MySQL GROUP BY clause behave like DISTINCT clause?

Srinivas Gorla
Srinivas Gorla
Updated on 22-Jun-2020 595 Views

When we use the GROUP BY clause in the SELECT statement without using aggregate functions then it would behave like the DISTINCT clause. For example, we have the following table −mysql> Select * from testing; +------+---------+---------+ | id   | fname   | Lname   | +------+---------+---------+ |  200 | Raman   | Kumar   | |  201 | Sahil   | Bhalla  | |  202 | Gaurav  | NULL    | |  203 | Aarav   | NULL    | |  204 | Harshit | Khurana | |  205 | Rahul   | NULL    | |  206 | ...

Read More

How we can find all the triggers associated with a particular MySQL table?

Arjun Thakur
Arjun Thakur
Updated on 22-Jun-2020 162 Views

We can find all the triggers associated with a particular table with the help of the following query −mysql> Select * from INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_SCHEMA = 'query'AND EVENT_OBJECT_TABLE = 'Student_info'\G *************************** 1. row ***************************            TRIGGER_CATALOG: def             TRIGGER_SCHEMA: query               TRIGGER_NAME: studentinfo_after_delete         EVENT_MANIPULATION: DELETE       EVENT_OBJECT_CATALOG: def        EVENT_OBJECT_SCHEMA: query         EVENT_OBJECT_TABLE: student_info               ACTION_ORDER: 1           ACTION_CONDITION: NULL           ...

Read More

How does ‘FOR EACH ROW’ work in the MySQL trigger?

Samual Sam
Samual Sam
Updated on 22-Jun-2020 6K+ Views

Actually ‘FOR EACH ROW’ means for each of the matched rows that get either updated or deleted. In other words, we can say that trigger is not applied to each row, it just says to execute the trigger body for each affected table row. We can illustrate this by the following example −ExampleIn this example, we are creating two tables, Sample and Sample_rowaffected, as follows −mysql> Create table Sample(id int, value varchar(20)); Query OK, 0 rows affected (0.47 sec) mysql> Insert into Sample(id, value) values(100, 'same'), (101, 'Different'), (500, 'excellent'), (501, 'temporary'); Query OK, 4 rows affected (0.04 sec) ...

Read More

What is the meaning of ‘empty set’ in MySQL result set?

Nitya Raut
Nitya Raut
Updated on 22-Jun-2020 5K+ Views

If there is ‘empty set’ in the result set of MySQL query then it means that MySQL is returning no rows and no error also in the query. It can be understood with the help of the following example −mysql> Select * from Student_info WHERE Name = 'ABCD'; Empty set (0.00 sec)We can see the empty set and execution time as output. It means that the query is correct but the MySQL table is not having the name ‘ABCD’.

Read More

How can we check the list of all triggers in a database?

Manikanth Mani
Manikanth Mani
Updated on 22-Jun-2020 246 Views

With the help of the SHOW TRIGGERS statement, we can list all the triggers in a particular database. It can be illustrated with the help of the following example −Examplemysql> Show Triggers\G *************************** 1. row ***************************   Trigger: trigger_before_delete_sample     Event: DELETE     Table: sample Statement: BEGIN SET @count = if (@count IS NULL, 1, (@count+1)); INSERT INTO sample_rowaffected values (@count); END   Timing: BEFORE  Created: 2017-11-21 12:31:58.70 sql_mode: ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERR OR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION              Definer: root@localhost character_set_client: cp850 collation_connection: cp850_general_ci   Database Collation: latin1_swedish_ci *************************** 2. ...

Read More

How can we discard a MySQL statement in the middle of its processing?

Prabhas
Prabhas
Updated on 22-Jun-2020 136 Views

With the help of \c command, we can discard a MySQL statement in the middle of its processing. Consider the following example in which in the middle of the statement we want to discard it then we use \c option for it −mysql> Select *    -> from\c mysql>The above query shows that after using \c option MySQL discards the statement and returns to the prompt.

Read More

What are the advantages, disadvantages and restrictions of using MySQL triggers?

Fendadis John
Fendadis John
Updated on 22-Jun-2020 5K+ Views

We must have to understand the advantages, disadvantages, and restrictions of using MySQL triggers so that we can use it effectively.AdvantagesFollowings are the advantages of using MySQL triggers −Integrity of data − With the help of MySQL trigger we can check the integrity of data in the table. In other words, MySQL triggers are the alternative way to check the integrity of data.Useful for catching errors − MySQL triggers can catch errors in business logic in the database layer.Alternative way to run scheduled tasks − Actually by using MySQL triggers we do not have to wait to run the scheduled tasks because ...

Read More

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

Govinda Sai
Govinda Sai
Updated on 22-Jun-2020 170 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
Showing 601–610 of 3,404 articles
« Prev 1 59 60 61 62 63 341 Next »
Advertisements