Query 1 – returns 217 rows:
select
cv.date, CV.continent, cv.location
from
PortfolioProjects..CovidVaccinations Cv
where
cv.date between '2024-01-01' and '2024-12-31'
and cv.location like 'NIGERIA'
order by 1
Query 2 – returns 217 rows:
select
date, total_cases, total_deaths
from
PortfolioProjects..CovidDeaths
where
date between '2024-01-01' and '2024-12-31'
and location like 'NIGERIA'
order by 1
Query 3 – which merges queries 1 and 2 – returns 54467 rows:
select
CV.date, cv.continent, CV.location,
cd.total_cases, CD.total_deaths
from
PortfolioProjects..CovidVaccinations CV
inner join
PortfolioProjects..CovidDeaths CD on CV.date = CD.date
where
CV.date between '2024-01-01' and '2024-12-31'
and cv.location like 'NIGERIA'
order by 1
How do I stop this happening?
I have tried using the distinct function as below, but it didn’t change the output
select
distinct(CV.date), cv.continent, CV.location,
cd.total_cases, CD.total_deaths
from
PortfolioProjects..CovidVaccinations CV
inner join
PortfolioProjects..CovidDeaths CD on CV.date = CD.date
where
CV.date between '2024-01-01' and '2024-12-31'
and cv.location like 'NIGERIA'
order by 1
New contributor
Idakwo F. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4