Found 4219 Articles for MySQLi

Can we use MySQL GROUP BY clause with multiple columns like MySQL DISTINCT clause is used?

varma
Updated on 14-Feb-2020 09:54:56

9K+ Views

Yes, it is possible to use MySQL GROUP BY clause with multiple columns just as we can use MySQL DISTINCT clause. Consider the following example in which we have used DISTINCT clause in first query and GROUP BY clause in the second query, on ‘fname’ and ‘Lname’ columns of the table named ‘testing’.mysql> Select * from testing; +------+---------+---------+ | id   | fname   | Lname   | +------+---------+---------+ |  200 | Raman   | Kumar   | |  201 | Sahil   | Bhalla  | |  202 | Gaurav  | NULL    | |  203 | Aarav   | ... Read More

How Can MySQL GROUP BY clause behave like DISTINCT clause?

Srinivas Gorla
Updated on 22-Jun-2020 12:05:00

428 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 to use MySQL DISTINCT clause on multiple columns?

usharani
Updated on 22-Jun-2020 12:05:52

5K+ 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 we destroy a trigger?

Monica Mona
Updated on 22-Jun-2020 12:07:19

293 Views

We can destroy a trigger in two ways −Dropping a trigger explicitlyWith the help of the DROP statement, we can destroy a trigger explicitly. It can be understood with the help of the following example −mysql> DROP Trigger before_inser_studentage1; Query OK, 0 rows affected (0.05 sec)Dropping a trigger implicitlyA trigger will be destroyed implicitly if the table with which it is associated is destroyed or if the database which it is associated is destroyed.

How can we get only unique values of a column in MySQL result set?

varun
Updated on 22-Jun-2020 12:08:27

1K+ Views

While querying data from a MySQL table, we may get duplicate values from a column. With the help of the DISTINCT clause in the SELECT statement, we can get rid of duplicate data in the result set.SyntaxSELECT DISTINCT Columns FROM Table_name WHERE conditions;ExampleFor example, we have a table named ‘tender’ having the following columns −mysql> Select * from tender; +----------+--------------+--------------+-------+ | clientid | client_Fname | Client_Lname | value | +----------+--------------+--------------+-------+ |      100 | Mohan        | Kumar        | 60000 | |      101 | Sohan        | Singh     ... Read More

How can we count a number of unique values in a column in MySQL table?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

181 Views

By using DISTINCT keyword along with column name as the argument of COUNT() function we can count the number of unique values in a column. The syntax is as follows − SELECT COUNT(DISTINCT Col_name) FROM table_name; Example Suppose we have the following table mysql> Select * from tender; +----------+--------------+--------------+-------+ | clientid | client_Fname | Client_Lname | value | +----------+--------------+--------------+-------+ | 100 | Mohan | Kumar | 60000 | | 101 | Sohan ... Read More

What are the privileges required to use triggers?

Moumita
Updated on 22-Jun-2020 12:09:13

167 Views

We must have SUPER privileges to create or destroy triggers with the help of a CREATE or DROP statement. Other than that if the triggered statements use OLD or NEW then there are some additional privileges as follows which we require −To assign the value of a column with SET NEW.column_name = value then we must have the UPDATE privilege for the column.To use NEW.column_name in an expression to refer to the new value of a column, we must have the SELECT privilege for the column.

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

Arjun Thakur
Updated on 22-Jun-2020 12:04:06

69 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 can we use INFORMATION_SCHEMA to get the details about triggers in a particular database?

Rishi Raj
Updated on 22-Jun-2020 12:06:26

81 Views

It can be done with the help of the following statement −mysql> select * from information_schema.triggers where     -> information_schema.triggers.trigger_schema like '%query%'\G *************************** 1. row ***************************             TRIGGER_CATALOG: def              TRIGGER_SCHEMA: query                TRIGGER_NAME: trigger_before_delete_sample          EVENT_MANIPULATION: DELETE        EVENT_OBJECT_CATALOG: def         EVENT_OBJECT_SCHEMA: query          EVENT_OBJECT_TABLE: sample                ACTION_ORDER: 1            ACTION_CONDITION: NULL            ACTION_STATEMENT: BEGIN SET @count ... Read More

How can we get the metadata of triggers?

Sharon Christine
Updated on 22-Jun-2020 11:46:12

118 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

Advertisements