DEV Community

Kiron Roy
Kiron Roy

Posted on • Updated on

Dream Team 1992 SQL

This article is a similar to my Scientists & Transport (SQL) Basics article.

I used data from my Dream Team 1992 C# console application:

and made a database in SSMS called DreamTeam92. You can open this in another window, it looks much better 🙂

This database has three tables:

  • Players
  • Positions
  • NBA Team

The tables:

Players Table data type
🔑 Id int
FirstName varchar(50)
LastName varchar(50)
Height float
Weight int
Age int

In the Players table, the Height field is a float data type, which is a decimal number with less accuracy. This field doesn't need to be precise, because we are not dealing with money. For Example, Michael Jordan's Height is 6'6", and in the field it is represented as 6.06
The Players table is the primary table, the other two are linked to it.

Positions Table data type
🔑 Id int
PlayerId int
Position varchar(50)
NBATeam Table data type
🔑 Id int
PlayerId int
TeamName varchar(50)

Here is the diagram of the three tables:

relationships


Here is slightly complicated query. It basically finds all the shooting guards on the Dream Team roster:

SELECT dbo.Players.FirstName
     , dbo.Players.LastName
     , dbo.Positions.Position
     , dbo.NBATeam.Team
     , dbo.Players.Height
FROM   
dbo.Players INNER JOIN 
dbo.Positions ON dbo.Players.Id = dbo.Positions.PlayerId 

INNER JOIN dbo.NBATeam ON dbo.Players.Id = dbo.NBATeam.PlayerId
WHERE (dbo.Positions.Position = 'Shooting Guard')
Enter fullscreen mode Exit fullscreen mode

The key part is the last statement

WHERE (dbo.Positions.Position = 'Shooting Guard')

-- Note there are two shooting guards: Michael Jordan and Clyde Drexler

Enter fullscreen mode Exit fullscreen mode

Here is the result of that in a SSMS view :

shooting_guards

Here is a query that selects players from the Utah Jazz


SELECT dbo.Players.FirstName, dbo.Players.LastName, dbo.NBATeam.Team
FROM dbo.Players INNER JOIN
     dbo.NBATeam ON dbo.Players.Id = dbo.NBATeam.PlayerId
WHERE (dbo.NBATeam.Team = 'Utah Jazz')

-- Note: John Stockon and Karl Malone played for the Utah Jazz and it was an amazing time
Enter fullscreen mode Exit fullscreen mode

Here is the result of that in a SSMS view :

utah_jazz

Discussion (0)