?
Solved

Problem with JOIN statement [Firebird]

Posted on 2009-05-17
3
Medium Priority
?
506 Views
Last Modified: 2013-12-09
Having problems with a join statement. The code itself is working, but it's not showing up all the records I want.

Lag = Teams in the database
Spelare = Players in the database

The "join Spelare S on L.Klubb" is joining the teams in the two tables.
My problem however, is that not all team's are added into Lag L which makes them not show up.

The only results shown are where the players have a team that's also added into the table Lag. If the team is not added there it doesn't show up (probably because of the joined statement and the "where NOT L.Division = 'NHL') ?

I want all records but NOT L.Division = 'NHL' to show up, even the ones that doesn't have a team in the Lag table.

Should I use NULL somehow to identify the "unknown" teams or something?
select S.* from Lag L join Spelare S on L.Klubb = S.Klubb where NOT L.Division = 'NHL'  and S.Rattigheter is null and S.Alder > 17 and S.Alder < 30 order by (S.Off+S.Def) * (S.Potential*4) / (S.Alder*3) DESC

Open in new window

0
Comment
Question by:MerlaP83
  • 2
3 Comments
 
LVL 19

Expert Comment

by:NickUpson
ID: 24406002
 

Open in new window

you need right join, 

Open in new window

select S.* from Lag L right join Spelare S on L.Klubb = S.Klubb where NOT L.Division = 'NHL'  and S.Rattigheter is null and S.Alder > 17 and S.Alder < 30 order by (S.Off+S.Def) * (S.Potential*4) / (S.Alder*3) DESC

Open in new window


0
 

Author Comment

by:MerlaP83
ID: 24406785
Unfortunately that didn't work.

The problem seems to be with where NOT L.Division = 'NHL'. If I remove that line, then everything is showing up. But I need to use that line as well to filter out some players - and if the player's team is not added to Lag, then it seems to skip that player, which is wrong.
0
 
LVL 19

Accepted Solution

by:
NickUpson earned 1000 total points
ID: 24406950
where ( L.Division <> 'NHL' or L.division is null)
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this article, we’ll look at how to deploy ProxySQL.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question