473,399 Members | 2,858 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,399 software developers and data experts.

Using Max In Subquery.

1
I am using max in following way at various places but here i am getting error that single single-row subquery returns more than one row. I made correction in following query by taking max as following max(c.company_name) ,that solves my problem...but that is not the requirement. Can any one help in this case
Please let me know asap to resolve this problem

select max ((select c.COMPANY_NAME
from companies c
where c.COMPANIES_ID in (
select distinct case when (select ta.transport_advis_id from transport_advis ta where ta.PACKING_NOTE_DETAILS_ID = pnd.PACKING_NOTE_DETAILS_ID and ta.deleted='N') is null
Then
Case
When pn.STATUS_CODES_ID = 50717
then
pn.companies_id
when pn.STATUS_CODES_ID = 50716
Then
pn.companies_id
Else
NULL
End
Else
to_number((select ta.carrier from transport_advis ta where ta.PACKING_NOTE_DETAILS_ID = pnd.PACKING_NOTE_DETAILS_ID and ta.deleted='N'))
End Carrier
from
packing_notes pn,
packing_note_details pnd,
order_details od
where pn.packing_notes_id = pnd.packing_notes_id
And pnd.order_details_id = od.order_details_id
and od.orders_id = 288541300)) from companies;
Mar 13 '07 #1
4 4687
amr
20
you must write after case the name of column
Mar 15 '07 #2
Dave44
153 100+
you must write after case the name of column
actually you dont "have" to alias it... but it sure makes it easier to reference if you need to :)
Mar 19 '07 #3
Dave44
153 100+
I am using max in following way at various places but here i am getting error that single single-row subquery returns more than one row. I made correction in following query by taking max as following max(c.company_name) ,that solves my problem...but that is not the requirement. Can any one help in this case
Please let me know asap to resolve this problem
When you say it is not the requirement, do you mean that it returns different results than what you want?

You can see why its giving the error without the max though right?

your query, as shown here, without the max() in place is saying for every row in the companies table return the results of the this large subquery. now that subquery is to return every row in the companies table where its id is in some list of ids (returned from another subquery).

it is conceptually no different than if i did this:
Expand|Select|Wrap|Line Numbers
  1. [138]dave@ORADB> SELECT (SELECT 1
  2.   2          FROM   DUAL
  3.   3          UNION
  4.   4          SELECT 2
  5.   5          FROM   DUAL)
  6.   6  FROM   DUAL;
  7. SELECT (SELECT 1
  8.         *
  9. ERROR at line 1:
  10. ORA-01427: single-row subquery returns more than one row
  11.  
the point is you can't have multiples rows returned for each row in the companies (source) table (the outer most query). So, yes, placing the max on there would limit the subquery to returning just 1 row which makes it a legal SQL statement.

So for me to help further i need to know what is it exactly that you are wanting returned?
Mar 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Murali | last post by:
Hi All I was reading thro the posting(s) of Thomas Kyte and his nifty approach to doing updates without the need for unnecessary correlated subqueries. An alternative to correlated subquery...
2
by: lev | last post by:
CREATE TABLE . ( NULL , , (44) ) ID is non-unique. I want to select all IDs where the last entry for that ID is of type 11.
2
by: coryjflynn | last post by:
I am try to update the Gender field for all females of a database with about 15,000 records. So how I started was by searching baby girl names on the web and manipulated some of there lists to...
3
by: olanorm | last post by:
I have a query where one or more of the columns returned is a result from a subquery. These columns get their own alias. I want to filter out the rows containing NULL from the subqueries but it...
6
by: J Smith | last post by:
After doing some googling through the lists and such, I wasn't able to arrive at a solution for a problem I've run into recently. I've seen mention of similar symptoms, but my case seems different....
11
by: Paul Reddin | last post by:
Hi, This is a real hopeful one! What we are trying to do: 1. We MUST present a mappable database object for our application objects i.e a Table or a View Some of the views are very...
8
by: Venkata C | last post by:
Hi! Does anyone here know of a way to goad DB2 into converting a correlated subquery to a non-correlated one? Does DB2 ever do such a conversion? We have a query of the form SELECT .. FROM A...
1
debasisdas
by: debasisdas | last post by:
Using Co-related sub query ======================== While a subquery is evaluated only once for each table, a correlated subquery is evaluated once for each row. Sub query can take value from...
3
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
1
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.