Unix Technical Forum

Return 1 row from joined table

This is a discussion on Return 1 row from joined table within the Oracle Miscellaneous forums, part of the Oracle Database category; --> I'm having a problem with this SQL string, I want 1 record from each joined salestrans table like for ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 05:27 AM
Mike Dole
 
Posts: n/a
Default Return 1 row from joined table

I'm having a problem with this SQL string, I want 1 record from each
joined salestrans table like for instance:

SALESNUMBE ITEMNUMBER
---------- --------------------
738744 6398000
738734 1201270
738737 2216000
738644 5251000
738694 5943000
737714 2401000
736774 5943000

But the following SQL string:

SELECT str.salesnumber, str.itemnumber FROM XAL_SUPERVISOR.SALESTRANS
STR, XAL_SUPERVISOR.SALESTABLE ST WHERE str.dataset = 'FIK' AND
st.dataset = 'FIK' AND st.salesnumber = str.salesnumber AND
st.DELIVERYDATE = TO_DATE('23-12-2004', 'DD/MM/YYYY') AND st.FIKRetbon
= 1 AND ROWNUM = 1

Returns only:

SALESNUMBE ITEMNUMBER
---------- --------------------
738744 6398000

Can someone please tell me how I solve this?

Thanks in advance,

Mike
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 05:27 AM
DA Morgan
 
Posts: n/a
Default Re: Return 1 row from joined table

Mike Dole wrote:
> I'm having a problem with this SQL string, I want 1 record from each
> joined salestrans table like for instance:
>
> SALESNUMBE ITEMNUMBER
> ---------- --------------------
> 738744 6398000
> 738734 1201270
> 738737 2216000
> 738644 5251000
> 738694 5943000
> 737714 2401000
> 736774 5943000
>
> But the following SQL string:
>
> SELECT str.salesnumber, str.itemnumber FROM XAL_SUPERVISOR.SALESTRANS
> STR, XAL_SUPERVISOR.SALESTABLE ST WHERE str.dataset = 'FIK' AND
> st.dataset = 'FIK' AND st.salesnumber = str.salesnumber AND
> st.DELIVERYDATE = TO_DATE('23-12-2004', 'DD/MM/YYYY') AND st.FIKRetbon
> = 1 AND ROWNUM = 1
>
> Returns only:
>
> SALESNUMBE ITEMNUMBER
> ---------- --------------------
> 738744 6398000
>
> Can someone please tell me how I solve this?
>
> Thanks in advance,
>
> Mike


AND ROWNUM = 1 guarantees the return of one and only one row no matter
the query.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace 'x' with 'u' to respond)


-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 05:27 AM
ak_tiredofspam@yahoo.com
 
Posts: n/a
Default Re: Return 1 row from joined table

have you tried ROW_NUMBER() OVER(...) ?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 05:27 AM
Ed Prochak
 
Posts: n/a
Default Re: Return 1 row from joined table

What is different about the rows? Using something like rownum=1 is a
kludge. It means you haven't identified all the conditions that are
unique to the solution set.

As a first pass, try removing the rownum condition, add a count(*) to
the select clause and the appropriate group by clause. If the counts
are all 1 then you never needed any other condition in the first place.
If they are not, you neee to think about what conditions you are
missing.

HTH
ed

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:09 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com