Home > front end >  How to compare all row values of a column against all different values of that column using SQL and
How to compare all row values of a column against all different values of that column using SQL and

Time:08-10

I have a column that has values like this I want to write an SQL statement to return values in two columns which will look like this.

[input] [1]: https://i.stack.imgur.com/j5GuT.png


[Output] [2]: https://i.stack.imgur.com/JHolu.png

CodePudding user response:

You just need to self JOIN your table with column value unequality condition like this

WITH data AS (
    SELECT * FROM (values ('a'), ('b'), ('c'), ('d')) t("column")
)
SELECT d1."column", d2."column"
FROM data d1
JOIN data d2 ON d1."column" != d2."column"
ORDER BY 1, 2

CodePudding user response:

select * from table t1 cross join table t2

  • Related