473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Join Issues

Dev
Hello all,

I have been working with joins and having alot of success up until now.

What I have is this:
SELECT a.merno
,g.mcmid
FROM (
total AS a LEFT JOIN mcmid AS g ON (g.merno=a.merno))
WHERE a.repno='111111'
AND a.month='2003-11-01'
AND g.month='2003-11-01'
ORDER BY merno

Currently it is returning only 178 records where it should be returning 407
records.
The 401 records are what are returned from the total table.

I beleave the problem is with the:
AND g.month='2003-11-01'

any clues?

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #1
1 1126
On Tue, 16 Dec 2003, Dev wrote:
Hello all,

I have been working with joins and having alot of success up until now.

What I have is this:
SELECT a.merno
,g.mcmid
FROM (
total AS a LEFT JOIN mcmid AS g ON (g.merno=a.merno))
WHERE a.repno='111111'
AND a.month='2003-11-01'
AND g.month='2003-11-01'
ORDER BY merno

Currently it is returning only 178 records where it should be returning 407
records.
The 401 records are what are returned from the total table.

I beleave the problem is with the:
AND g.month='2003-11-01'

any clues?


By saying g.month = '2003-11-01' in the where you've effectively removed
the outerness of the join. If there's no matching g row for
g.merno=a.merno, it extends the a row with nulls for the g column and then
will be checking g.month='2003-11-01' which will return unknown because
the g row has a null for month. Depending on the behavior you want,
either you'd want AND (g.month is null or g.month='2003-11-01') in the
where or you want the month clause in the ON at which point it's taken
into account for determining if there's a matching row.

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul Bramscher | last post by:
Here's one for pathological SQL programmers. I've got a table of things called elements. They're components, sort of like amino acids, which come together to form complex web pages -- as nodes...
1
by: Eric | last post by:
Hi Folks, Lets assume I have three tables. Their layout is as follows. Please note that tblPeople does not have an entry for Denver (this is my problem) tblCity _________________ CityName ...
1
by: tekanet | last post by:
Hello folks, first of all I really don't know how you gurus call this way of writing joins: SELECT A.FIELD, B.FIELD FROM TABLE_A A, TABLE_B B
7
by: steve | last post by:
Can you join two tables across different servers in mySQL, or am I dreaming of Oracle? -- Posted using the http://www.dbforumz.com interface, at author's request Articles individually checked...
3
by: Jack Smith | last post by:
Hello, I want to be able to view data from 3 tables using the JOIN statement, but I'm not sure of how to do it. I think i don't know the syntax of the joins.I imagine this is easy for the...
0
by: Vendell | last post by:
Join one of Canada's finest business men... Dear entrepreneur colleague: Here is a message from the founder.... Let me introduce myself. My name is Ariel Topf. I am 42 years old and I have...
0
by: yeahuh | last post by:
Quick and dirty version. Godaddy server using MySQL 4.0.24 I’m trying a left join to obtain id’s in table A(cars) that are NOT in car_id in table B(newspaper): *This is a cut down version...
7
by: dunleav1 | last post by:
I have an application that uses the old join syntax instead of the SQL92 standards join syntax. I need to justify changing the code to the new standard. Is there any performance issue related to...
2
by: cj | last post by:
My code below gives me "SQL: Column 'BTN' is not found." It will work if I use an inner join or just join but those two joins don't return all the rows. BTN has 5 rows, but arcust01 has only has...
1
by: Eps | last post by:
I understand that if I want to wait for a thread to stop then I can use the join menthod. If I have more than one thread, and I want to wait until they have all stopped, what is the best way of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.