Solved

Problem with JOIN statement [Firebird]

Posted on 2009-05-17
3
495 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 250 total points
ID: 24406950
where ( L.Division <> 'NHL' or L.division is null)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now