SQL Miscellaneous across Pivot Tables

I am trying to get the DISTINCT value of a single column in a table. However, this column is INNER JOINED from another table via id .

When I try to use DISTINCT in a column, it gives the same results, because DISTINCT also takes into account the unique identifier identifier. Is there any work for this to just get the value of a DISTINCT column from a joined table ???

EG.

 SELECT val1, b.val2, val3 FROM TABLE 1 JOIN (SELECT DISTINCT val2 FROM TABLE 2) AS b ON val1 = b.val2 
+4
source share
2 answers

To provide my solution: I ended up using nested elements through the connection, and all unnecessary values ​​(all 20+) of them should have been wrapped around MIN (x), seeing that these values ​​are not significant, if only one separate value is returned .

0
source

Try throwing at GROUP BY instead of DISTINCT:

 SELECT val1 , b.val2 , val3 FROM TABLE 1 JOIN (SELECT val2 FROM TABLE 2 GROUP BY val2) AS b ON val1 = b.val2 
+5
source

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


All Articles