Home » SQL & PL/SQL » SQL & PL/SQL » How to Combine data in a single SQL statement of two different clauses.
How to Combine data in a single SQL statement of two different clauses. [message #264678] Tue, 04 September 2007 03:02 Go to next message
saikumar.mvvr
Messages: 18
Registered: September 2007
Location: India
Junior Member

Dear All,

I have a SQL which is based on 5 tables. here i have the following conditions.

this sql am calling as cursor. And i have two conditions.

i have table data like this.

Table123

C1 C2
========
1 1
1 2
1 3
2 1
2 2
2 3
3 4
3 5
3 6

if c1=c2 then the sql which i have written will pickup and put it into a flat file. i.e i will get records of C1 values 1 & 2, i will not get for C1 value 3, as it is not satisfying condition c1=c2. for this case i need take this record as well some thing like c1=3 and c2=3 (if it is not satisfying the condition i would like to make c2 as c1).

Can any one tell me the way to combine the above said in one sql statement.

thx
Sai Kumar.
Re: How to Combine data in a single SQL statement of two different clauses. [message #264681 is a reply to message #264678] Tue, 04 September 2007 03:12 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
hi,

not sure of what you mean by this:

Quote:
for this case i need take this record as well some thing like c1=3 and c2=3 (if it is not satisfying the condition i would like to make c2 as c1


anyways can you show us what you did?


regards,
Re: How to Combine data in a single SQL statement of two different clauses. [message #264689 is a reply to message #264681] Tue, 04 September 2007 03:29 Go to previous messageGo to next message
saikumar.mvvr
Messages: 18
Registered: September 2007
Location: India
Junior Member

sure.

this is the basic sql

select ship.billcust
, ship.shipcust
, ship.shipcity
, ship.countrycd
, ship.language
, ship.compno
, bsi.stocknosu
, lib.name1
, lib.name2
, lib.city
, lib.currency
from interface_tbl int
, ship_to_customer ship
, bsiiness bsi
, libl_to_customer lib
, customer ship
where int.status in ('E','W')
and int.system = 'MF'
and int.intype = 'CM'
and ship.custno = int.czifref
and bsi.custno = ship.custno
and bsi.compno = ship.compno
and lib.billcust = ship.billcust
and ship.shipcust = lib.shipcust


which get the data of shipcust=billcust. now i would like to add the customers which are not shipcust=billcust.

now i have even the query to find out where shipcust!=billcust.

select billcust from ship_to_customer
minus
select billcust from ship_to_customer where billcust = shipcust

this gives me the customers which are not having same value. now i would like to have a single query. where i can combine these two. if shipcust=billcust i need to data as it is, and if shipcust!=billcust then i need to populate data shipcust=billcust.

this is what i am looking for..

Re: How to Combine data in a single SQL statement of two different clauses. [message #264694 is a reply to message #264689] Tue, 04 September 2007 03:51 Go to previous message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read and follow OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format. Use the "Preview Message" button.
Please always post your Oracle version (4 decimals).

Regards
Michel
Previous Topic: How many Primary keys can a table have???
Next Topic: Trying (and failing) to use PL/SQL variable in a XML query in a cursor
Goto Forum:
  


Current Time: Thu Dec 08 12:40:31 CST 2016

Total time taken to generate the page: 0.11528 seconds