Aliases of a string in sql?

Hi!

Feature request:

Select * 
FROM calendar_year as cal
LEFT JOIN album as alb ON alb.year = cal.year AND (alb.band_id = 388)
WHERE cal.year BETWEEN 1969 AND 1982


In the resulting jeune 2 columns with the same name "year", obtained from different tables - album and calendar_year

Question:
How do I set aliases for the columns "year" to join the already obtained? I would like to output the number of values in the year column with the query

SELECT COUNT(ooo.year)
FROM
(Select *
FROM calendar_year as cal
LEFT JOIN album as alb ON alb.year = cal.year AND (alb.band_id = 388)
WHERE cal.year BETWEEN 1969 AND 1982) as Ltd


But gives the error "ERROR: ambiguous reference to a column "year"", which is logical, because in table 2 the columns with the same name
March 25th 20 at 12:40
3 answers
March 25th 20 at 12:42
Solution
Something like this
SELECT 
COUNT(ooo.year_alb)
FROM
(
SELECT
 alb.year AS year_alb,
 cal.year AS year_cal
FROM
 calendar_year cal
 LEFT JOIN album alb ON alb.year = cal.year AND (alb.band_id = 388)
 WHERE 
 cal.year BETWEEN 1969 AND 1982
 ) Ltd


year - name of the column, better to be quoted, `year` - so for MySQL, or "year" for PostgreSQL
Thanks, based on your reply I managed to create the correct query - Francesco commented on March 25th 20 at 12:45
March 25th 20 at 12:44
Remove the * and list all the desired columns in the format table.column
Thank you! - Francesco commented on March 25th 20 at 12:47
March 25th 20 at 12:46
so for example:
select alb.year as year1, cal.year as year2
Thanks, based on your reply I managed to create the correct query - Francesco commented on March 25th 20 at 12:49

Find more questions by tags SQL