I am somewhat stumped on a seemingly simple problem. I have a table set up such as,
CREATE TABLE cities (
column_1 TEXT,
column_2 TEXT);
Where the contents of these tables look like
column_1 | column_2
---------------------
Atlanta | Atlanta
Boston | Chicago
Chicago | Los Angeles
Seattle | Tacoma
NULL | Seattle
What query could I run that would look at both of these columns, and despite their order, return where the two columns matchup?
The result I am looking for would be:
column_1 | column_2
---------------------
Atlanta | Atlanta
Chicago | Chicago
Seattle | Seattle
I have tried:
SELECT *
FROM cities
WHERE column_1 = column_2;
But this only returns the EXACT matches:
column_1 | column_2
---------------------
Atlanta | Atlanta
You just need a self join:
SELECT c1.column_1, c2.column_2
FROM cities c1
JOIN cities c2
ON c1.column_1 = c2.column_2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With