Can a "Distinguished" Word be used twice in a single select query?

Can a "Different" Word be used twice in a single query of choice? how wise:

select DISTINCT(trackid), DISTINCT(table_name) 
from jos_audittrail 
where live = 0 AND operation = UPDATE

thank

+3
source share
4 answers

No, by default Distinct works in all selected columns. eg.

select DISTINCT trackid, table_name 
from jos_audittrail 
where live = 0 AND operation = UPDATE

Here, the entire individual combination of tracks and tables will be selected.

EDIT

To get other entries other than this, you can use davek's answer. He will work.

You can use group byto perform this work as a group, it applies to both columns that are provided, so the aggregate function is not required.

    SELECT trackid, table_name FROM jos_audittrail 
    WHERE live = 0 AND operation = 'UPDATE' 
    GROUP BY trackid, tablename
+4
source
select trackid
, table_name
, count(*)
from jos_audittrail 
where live = 0 AND operation = UPDATE
group by trackid, table_name
order by trackid, table_name

.

+2

No. You cannot use this, it will cause an error, but there are other alternatives where you can come up with to get the desired results.

+2
source

The easiest way to find this is to simply run the query. I just tried and it didn’t work.

however, you can use two columns in GROUP BY- just do the following:

select trackid, table_name from jos_audittrail where live = 0 and operation = 'UPDATE' group by trackid, tablename
0
source

Source: https://habr.com/ru/post/1743492/


All Articles