Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selecting columns from table after joining in SQL

is there a difference between specifying the table-column after joining tables?

For example, in the below queries I selected the columns as b.refunded_at or refunded_at. The output the same, but I just want to make sure.

Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT billing_cycle_in_months,
MIN(DATEDIFF(refunded_at, settled_at)) AS min_days,
AVG(DATEDIFF(refunded_at, settled_at)) AS avg_days,
MAX(DATEDIFF(refunded_at, settled_at)) AS max_days
FROM noom_signups AS a
JOIN noom_transactions AS b ON a.signup_id = b.signup_id
JOIN noom_plans AS c ON a.plan_id = c.plan_id
WHERE started_at >= 2019-01-01
GROUP BY 1;

and

SELECT billing_cycle_in_months,
MIN(DATEDIFF(b.refunded_at, b.settled_at)) AS min_days,
AVG(DATEDIFF(b.refunded_at, b.settled_at)) AS avg_days,
MAX(DATEDIFF(b.refunded_at, b.settled_at)) AS max_days
FROM noom_signups AS a
JOIN noom_transactions AS b ON a.signup_id = b.signup_id
JOIN noom_plans AS c ON a.plan_id = c.plan_id
WHERE a.started_at >= 2019-01-01
GROUP BY 1;

>Solution :

Tables do not have to be specified so long as the column names are unambiguous.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading