Skip to content
Advertisement

How to query the number of records when there is the DISTINCT keyword in the SQL multi-table join query string?

— table1 has 1 record

— table2 has 4 record

— t_test01.value = t_test02.value, 3 record

— DISTINCT t_test01.value = t_test02.value, 1 record

How to query the number of records when there is the DISTINCT keyword in the SQL multi-table join query string?

Advertisement

Answer

A quick-and-dirty approach is to use strings:

Otherwise, you can use a subquery or CTE:

Note the use of proper, explicit, standard, readable JOIN syntax in both cases. Never use commas in the FROM clause.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement