Skip to content
Advertisement

joining two columns sql query

world! I’m currently stuck on this problem where i want to join two columns and run the select statement of the two, but i’m getting errors; these are the columns i want to join:

and

where in the second, for every row, i count how many equal rows i have for each value.

the two columns values: first column second column

i dont know how to have both of them next to each other as a normal select statement: SELECT column_1, column_2 FROM table;

Advertisement

Answer

You do not want to use an analytic function for this as you will find the COUNT for all the rows and then use DISTINCT to discard rows which involves lots of unnecessary calculation.

Instead, it is much more efficient GROUP BY the column_name and then aggregate so that you only generate a single row for each group to start with:

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