473,378 Members | 1,479 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,378 software developers and data experts.

brain cramp or bug: inner join returns rows w/null

running 8.1.7 server, 8.1.6 client.

i *thought* inner join should not return nulls, but not only that,
but i get way more rows than i'm expecting.

assume:

order table:
order_number

order_line table:
order_number
order_line_number
value

assume 1,000 order rows, 20,000 order_line rows all have an
order_number and value.

the following:

select value from order_line, order
where order_line.order_number = order.order_number

returns rows with value = null

??

not only that, but the number of returned rows is app 65,000.

brain cramp or bug???

thanks,
robert
Jul 19 '05 #1
7 4422
Robert,

Brain cramp.

An inner join is essentially a cartesian product of the 2 tables with
filtering based on your "where" clause.

The number of rows returned could have been as much as 20,000,000.

The nulls that you are refering to are fine, since that's not one of the
columns with which you joined the tables.

Regards... Jon

Jon Armstrong
"robert" <gn*****@rcn.com> wrote in message
news:da**************************@posting.google.c om...
running 8.1.7 server, 8.1.6 client.

i *thought* inner join should not return nulls, but not only that,
but i get way more rows than i'm expecting.

assume:

order table:
order_number

order_line table:
order_number
order_line_number
value

assume 1,000 order rows, 20,000 order_line rows all have an
order_number and value.

the following:

select value from order_line, order
where order_line.order_number = order.order_number

returns rows with value = null

??

not only that, but the number of returned rows is app 65,000.

brain cramp or bug???

thanks,
robert



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 19 '05 #2
"Jon Armstrong" <no*******@noaddress.org> wrote in message news:<40**********@corp.newsgroups.com>...
Robert,

Brain cramp.

An inner join is essentially a cartesian product of the 2 tables with
filtering based on your "where" clause.

The number of rows returned could have been as much as 20,000,000.
a failure of old style syntax. the "logic" of the inner join is to
return a result set with, at maximum, the number of rows of the larger
table. this is why it's "inner". if executed as a nested-loop,
it will: read each order_line row, find its order, print the result
table row. 20,000 rows. since there is a condition, why does oracle
not execute as if a nested-loop??

(still doesn't explain why value could ever be NULL; i've restricted
to matching on order_number in both tables. all order_lines have
a value )

but, i suspect, because we have to refer to order in the from phrase,
we get the product.

if i had 9i around, i could check it. using sql-92 syntax on DB2/UDB,
i don't remember running into this.

thanks,
robert

The nulls that you are refering to are fine, since that's not one of the
columns with which you joined the tables.

Regards... Jon

Jon Armstrong
"robert" <gn*****@rcn.com> wrote in message
news:da**************************@posting.google.c om...
running 8.1.7 server, 8.1.6 client.

i *thought* inner join should not return nulls, but not only that,
but i get way more rows than i'm expecting.

assume:

order table:
order_number

order_line table:
order_number
order_line_number
value

assume 1,000 order rows, 20,000 order_line rows all have an
order_number and value.

the following:

select value from order_line, order
where order_line.order_number = order.order_number

returns rows with value = null

??

not only that, but the number of returned rows is app 65,000.

brain cramp or bug???

thanks,
robert



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 19 '05 #3

"robert" <gn*****@rcn.com> wrote in message
news:da**************************@posting.google.c om...
(still doesn't explain why value could ever be NULL; i've restricted
to matching on order_number in both tables. all order_lines have
a value )


I didn't catch this point the first time around. Did you say this earlier?

Test your data to make sure this is true. Maybe there's something about the
data that's different than what you expect.

Also, take a look at Oracle's execution plan to make sure that it's not
doing an outer join, for some reason.
Jul 19 '05 #4
"Laconic2" <la******@comcast.net> wrote in message news:<UJ********************@comcast.com>...
"robert" <gn*****@rcn.com> wrote in message
news:da**************************@posting.google.c om...
(still doesn't explain why value could ever be NULL; i've restricted
to matching on order_number in both tables. all order_lines have
a value )


I didn't catch this point the first time around. Did you say this earlier?

Test your data to make sure this is true. Maybe there's something about the
data that's different than what you expect.

Also, take a look at Oracle's execution plan to make sure that it's not
doing an outer join, for some reason.


if i add a group by i get the "correct" number of rows. ah. this
forces a cursor, which resolves at the row level, etc.

the mystery continues.

robert
Jul 19 '05 #5
Robert,

Try the three queries shown below.

1) select count(1) from order_line group by order_number having count(1)>1

2) select count(1) from order group by order_number having count(1)>1

If you find (and you will) any non-zero results above, that's the reason you
are seeing a number of rows in your result set greater than the largest
table. There's no mystery here. You have duplicates, unless your
description is incorrect.

3) select count(1) from order_line where value is null;

This will show null values if your description matches your actual data.

Regards... Jon

An inner join is essentially a cartesian product of the 2 tables with
filtering based on your "where" clause.

The number of rows returned could have been as much as 20,000,000.
a failure of old style syntax. the "logic" of the inner join is to
return a result set with, at maximum, the number of rows of the larger
table. this is why it's "inner".

Not exactly correct. This is data and criteria dependent. If the criteria
provides no actual restriction based on the given data, the result set will
contain N1 x N2 records, where N1 and N2 are the total number of rows in
each table.

Look for duplicates in your data. (See above)

With proper data and sql criteria, you would see the behavior you were
looking for. But that doesn't appear to be the case here.

if executed as a nested-loop,
it will: read each order_line row, find its order, print the result
table row. 20,000 rows. since there is a condition, why does oracle
not execute as if a nested-loop??

(still doesn't explain why value could ever be NULL; i've restricted
to matching on order_number in both tables. all order_lines have
a value )

Re-check your data. According to your description, you do have null values.
(See above)

but, i suspect, because we have to refer to order in the from phrase, we get the product.

if i had 9i around, i could check it. using sql-92 syntax on DB2/UDB,
i don't remember running into this.

thanks,
robert

The nulls that you are refering to are fine, since that's not one of the
columns with which you joined the tables.

Regards... Jon

Jon Armstrong
"robert" <gn*****@rcn.com> wrote in message
news:da**************************@posting.google.c om...
running 8.1.7 server, 8.1.6 client.

i *thought* inner join should not return nulls, but not only that,
but i get way more rows than i'm expecting.

assume:

order table:
order_number

order_line table:
order_number
order_line_number
value

assume 1,000 order rows, 20,000 order_line rows all have an
order_number and value.

the following:

select value from order_line, order
where order_line.order_number = order.order_number

returns rows with value = null

??

not only that, but the number of returned rows is app 65,000.

brain cramp or bug???

thanks,
robert



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 19 '05 #6

"robert" <gn*****@rcn.comwrote in message
news:da**************************@posting.google.c om...
(still doesn't explain why value could ever be NULL; i've restricted
to matching on order_number in both tables. all order_lines have
a value )
I didn't catch this point the first time around. Did you say this earlier?

Test your data to make sure this is true. Maybe there's something about the
data that's different than what you expect.

Also, take a look at Oracle's execution plan to make sure that it's not
doing an outer join, for some reason.
Jun 27 '08 #7
"Laconic2" <la******@comcast.netwrote in message news:<UJ********************@comcast.com>...
"robert" <gn*****@rcn.comwrote in message
news:da**************************@posting.google.c om...
(still doesn't explain why value could ever be NULL; i've restricted
to matching on order_number in both tables. all order_lines have
a value )

I didn't catch this point the first time around. Did you say this earlier?

Test your data to make sure this is true. Maybe there's something about the
data that's different than what you expect.

Also, take a look at Oracle's execution plan to make sure that it's not
doing an outer join, for some reason.
if i add a group by i get the "correct" number of rows. ah. this
forces a cursor, which resolves at the row level, etc.

the mystery continues.

robert
Jun 27 '08 #8

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

Similar topics

14
by: Stephan Diehl | last post by:
I was playing around with defining new types and have seen the following behaviour: Python 2.3.1 ============ >>> class Int(int):pass .... >>> a = Int(7) >>> b = Int(8)
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
3
by: mheydman | last post by:
I apologize if this has been asked before- I searched google but could not find a concrete answer. I recently inherited a database whose t-sql code is written in a format that I find difficult...
6
by: Steven D.Arnold | last post by:
I have a query which does not use column indexes that it should use. I have discovered some interesting behaviors of Postgres which may indicate a bug in the database's query planning. Take a...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
18
by: Dave | last post by:
Guys I am really stuck on this one. Any help or suggestions would be appreciated. We have a large table which seemed to just hit some kind of threshold. They query is somewhat responsive when...
3
by: Zeff | last post by:
Hi all, I have a relational database, where all info is kept in separate tables and just the id's from those tables are stored in one central table (tblMaster)... I want to perform a query, so...
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.