When select two columns with the same name from two different tables produces incorrect results

If you have two columns named the same thing from two different joined tables, results of the second one get mashed together in the results from both columns, and not displayed correctly.
(eg, the TYPE table from interface_details and interface_addresses

How they get displayed depends on which order they are called, and neither is correct

eg:


SELECT
interface_details.type,
interface_addresses.type
FROM interface_addresses
join interface_details
vs:

SELECT
interface_addresses.type,
interface_details.type
FROM interface_addresses
join interface_details
Parents
  • When you have a query that has the same col name from different tables you should explicitly give that col a name for results like below

    SELECT
       id.interface 'Interface',
       id.type 'Interface Details Type',
       ia.type 'Interface Address Type'
    FROM interface_addresses ia
       JOIN interface_details id ON id.interface = ia.interface;
     
     
Reply
  • When you have a query that has the same col name from different tables you should explicitly give that col a name for results like below

    SELECT
       id.interface 'Interface',
       id.type 'Interface Details Type',
       ia.type 'Interface Address Type'
    FROM interface_addresses ia
       JOIN interface_details id ON id.interface = ia.interface;
     
     
Children
No Data