I am running a simple query and asking to return the same column from the same table twice. For some reason, the column returns with two different results. Can someone please explain why and show me how to ask the query to return consistent results twice?
Here is the code I am running:
SELECT WIN1.SERVERNAME, WIN1.APPLICATION AS 'App 1', WIN1.STATUS AS 'Status 1', WIN1.IPADDRESS AS 'WIN1 IP', WIN2.APPLICATION AS 'App 2', WIN2.STATUS AS 'Status 2', WIN2.IPADDRESS AS 'WIN2 IP' FROM SERVER.WINDOWS WIN1, SERVER.WINDOWS WIN2 WHERE WIN1.IPADDRESS IS NOT NULL AND WIN2.IPADDRESS IS NOT NULL AND WIN1.SERVERNAME LIKE '%SERVER NAME%' AND WIN1.STATUS LIKE '%line%' AND WIN2.STATUS LIKE '%line%' AND WIN2.APPLICATION LIKE '%APPLICATION NAME%'
Thank you in advance.
Advertisement
Answer
By adding the same table twice to your query is similar to doing a full outer join, you are joining the table against itself, the where clauses make things harder to figure it out, just call the query without any filter to understand the effect of the query calling the same table twice.
From this point you should be able to accomplish what you are looking for.
SELECT WIN1.SERVERNAME, WIN1.APPLICATION AS 'App 1', WIN1.STATUS AS 'Status 1', WIN1.IPADDRESS AS 'WIN1 IP', WIN2.APPLICATION AS 'App 2', WIN2.STATUS AS 'Status 2', WIN2.IPADDRESS AS 'WIN2 IP' FROM SERVER.WINDOWS WIN1, SERVER.WINDOWS WIN2
OR
Select * FROM SERVER.WINDOWS WIN1, SERVER.WINDOWS WIN2