Question

Let's say I have a table named "mytable01". When I want to have two instances of the table in the query I do this:

SELECT t1.column, t2.column
FROM mytable01 t1, mytable01 t2;

Now, there are times that I want two instances from the same nested SELECT. Is there a way to do it without having to write it two times?

No correct solution

OTHER TIPS

No! You want to do a self-join (joining the table with itself) you must to declare it each time. By the way try to avoid write queries in implicit format and use explicit join pattern like it:

select t1.column, t2.column
from table t1
join table t2 on t2.id = t1.parentid

btw again, you example missed the columns for the join and that ill force a cross join.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top