Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to figure out what the correct syntax for UNION is. My schema looks

ID: 3680374 • Letter: I

Question

I am trying to figure out what the correct syntax for UNION is. My schema looks like is the following:

I need to print all teamIDs where the team played against the X team but not against the Y team.

So my first idea was to check for the hometeamNum and then do a check for the guesteamNum, but I am not sure how to do the proper syntax.

I am trying to figure out what the correct syntax for UNION is. My schema looks like is the following:

  Players (playerNum, playerName, team, position, birthYear)  Teams = (teamID, teamName, home, leagueName)  Games = (gameID, homeTeamNum, guestTeamNum, date)  

I need to print all teamIDs where the team played against the X team but not against the Y team.

So my first idea was to check for the hometeamNum and then do a check for the guesteamNum, but I am not sure how to do the proper syntax.

  SELECT DISTINCT hometeamNum   FROM games   WHERE       guestteamNum IN         (SELECT teamid FROM teams WHERE teamname = 'X') AND       guestteamNum NOT IN         (SELECT teamid FROM teams WHERE teamname = 'Y')   UNION DISTINCT  

Explanation / Answer

UNION: Union combines the results of two or more select commands. It gives distinct values. if we need to echo all values we can use UNION ALL command. For ur quiery we can find the result without UNION.

U can do it in multiple ways,


SELECT * INTO #XTeams FROM Teams teamname = 'Y';



SELECT DISTINCT hometeamNum FROM games WHERE guestteamNum IN (SELECT teamid FROM teams WHERE teamname = 'X' AND TeamId NOTIN (SELECT TeamId FROM #XTeams);

Union and And are cnnot combined together at same level of statement or condition.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote