Home » SQL & PL/SQL » SQL & PL/SQL » EXISTS SQL QUERY
EXISTS SQL QUERY [message #635025] Thu, 19 March 2015 05:05 Go to next message
palpali
Messages: 138
Registered: December 2014
Location: India
Senior Member
Hallo

I would like to share my Problem and would like to have your Suggestion and help.
I have two tables and and data in it (which i have pasted here for your reference)
and i am trying to make a query, which gives me Output as:

when the logistic.status = I then it should Display all the Logis
when the logistic.status = A then it should Display all other Logis but not that which has the statuis is A.

my code:

create table Testbooks (
  book_id number,
  book_name varchar2(30),
  preis number,
  logis number
  );

  insert into Testbooks (book_id, book_name, preis, logis) values (45, 'Oracle Tools', 80, 2);
  insert into Testbooks (book_id, book_name, preis, logis) values (50, 'Oracle for Beginners', 120, 5);
  insert into Testbooks (book_id, book_name, preis, logis) values (60, 'Advanced SQL', 50, 2);
  insert into Testbooks (book_id, book_name, preis, logis) values (55, 'Advancd Oracle', 150, 5);
  insert into Testbooks (book_id, book_name, preis, logis) values (35, 'JAVA Beginners', 60, 2);  
  
  commit;

create table logistic (
       logis number,            
       s_loc varchar2(20),
       status varchar2(1)
   );

  insert into logistic (logis, s_loc, status) values (2, 'ABC', 'A');     -- A = Active
  insert into logistic (logis, s_loc, status) values (1, 'MOON', 'I');    -- I = Inactive

commit;

and i have tried with this query but could not get the Output of my requirement :/

select  Testbooks.logis from Testbooks where exists (select logis from  logistic where status = 'I');


I thank you all in advance.


Re: EXISTS SQL QUERY [message #635028 is a reply to message #635025] Thu, 19 March 2015 05:55 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
You have not provided any insert for LOGIS value as 1 in the table Testbooks . So, how to validate the rule you have mentioned? Also, please show your desired output.

[Updated on: Thu, 19 March 2015 05:56]

Report message to a moderator

Re: EXISTS SQL QUERY [message #635030 is a reply to message #635025] Thu, 19 March 2015 06:12 Go to previous messageGo to next message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
when the logistic.status = I then it should Display all the Logis
when the logistic.status = A then it should Display all other Logis but not that which has the statuis is A


When logistic.status of what?

Re: EXISTS SQL QUERY [message #635032 is a reply to message #635030] Thu, 19 March 2015 06:37 Go to previous messageGo to next message
palpali
Messages: 138
Registered: December 2014
Location: India
Senior Member
hallo
ya its, just a Status, if Status = A then should diplay all other except that Logis which has Status = A
and if Status = I then should Display all logis
Re: EXISTS SQL QUERY [message #635033 is a reply to message #635032] Thu, 19 March 2015 06:44 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Do mean - display all books where the status in the corresponding logistics record has a status of I?
sql [message #635036 is a reply to message #635033] Thu, 19 March 2015 06:57 Go to previous messageGo to next message
sanodani
Messages: 98
Registered: October 2014
Member
can you

[Updated on: Thu, 19 March 2015 06:58]

Report message to a moderator

Re: sql [message #635038 is a reply to message #635036] Thu, 19 March 2015 07:00 Go to previous messageGo to next message
palpali
Messages: 138
Registered: December 2014
Location: India
Senior Member
Hallo cookiemonster..
yes, i would like to Display all the records if STATUS = I and if STATUS = A then should Display all other records except whose STATUS = A.

thankx
Re: sql [message #635040 is a reply to message #635038] Thu, 19 March 2015 07:01 Go to previous messageGo to next message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Once again, status of what?
Once again, SHOW US the result you want from the data you gave.

Re: sql [message #635043 is a reply to message #635040] Thu, 19 March 2015 07:17 Go to previous messageGo to next message
palpali
Messages: 138
Registered: December 2014
Location: India
Senior Member
I dont have my result now, coz' i m try to get my output but i am getting confusion to make a query to get my Output.. sry Michel....

as i would like to query, if the Status of Logis = I then should Display all books and Logis
and if Status of Logis = A then should Display all other books and Logis except those Logis whose Status = A is.

thank you
Re: sql [message #635045 is a reply to message #635043] Thu, 19 March 2015 07:35 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
If you mean to apply those rules while fetching rows from both the tables using SQL, then you would anyway get all the rows since there exists a row in logistic table with the status as 'I'. SO, you need to be clear that how you want to apply this condition? From where are you expecting the value to be applied in the filter predicate? Are these values to be passed via application? Or, you just want to query the tables to get desired rows? IT is not at all clear what you want.
Re: sql [message #635046 is a reply to message #635045] Thu, 19 March 2015 07:39 Go to previous messageGo to next message
palpali
Messages: 138
Registered: December 2014
Location: India
Senior Member
Hallo Lalit,

yes i want to query the tables to fetch the rows as per condition,
Re: sql [message #635048 is a reply to message #635046] Thu, 19 March 2015 08:04 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
palpali wrote on Thu, 19 March 2015 18:09

yes i want to query the tables to fetch the rows as per condition,


Lalit Kumar B wrote on Thu, 19 March 2015 18:05
you would anyway get all the rows since there exists a row in logistic table with the status as 'I'.


It's just like fetching a subset along with all the elements of the set. How would you filter the subset when you are ALSO looking for all the elements of the set?
Re: sql [message #635050 is a reply to message #635043] Thu, 19 March 2015 08:40 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
What I wrote here:
cookiemonster wrote on Thu, 19 March 2015 11:44
Do mean - display all books where the status in the corresponding logistics record has a status of I?


does not appear to be the same as what you wrote here, despite the fact that you apparently agree with me
palpali wrote on Thu, 19 March 2015 12:00
Hallo cookiemonster..
yes, i would like to Display all the records if STATUS = I and if STATUS = A then should Display all other records except whose STATUS = A.

thankx


Simply: If you just want records where the status is I then why mention status A at all?

palpali wrote on Thu, 19 March 2015 12:17
I dont have my result now, coz' i m try to get my output but i am getting confusion to make a query to get my Output.. sry Michel....


You know what the output should be based on the data you have (if not then you have no idea what you're trying to do and we can't possibly help you). So just write out what the output should be and show us, then we might be able to tell you what query you use to get it.
Also you need to specify what the relationship is between the tables.
Re: EXISTS SQL QUERY [message #635058 is a reply to message #635025] Thu, 19 March 2015 10:16 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>when the logistic.status = I then it should Display all the Logis

"all" above is different from "all" below & I am unclear what should be returned for both above & below.

>when the logistic.status = A then it should Display all other Logis but not that which has the statuis is A.

How will you & I know when the correct solution has been posted to this thread?
Re: EXISTS SQL QUERY [message #635077 is a reply to message #635058] Thu, 19 March 2015 14:41 Go to previous messageGo to next message
palpali
Messages: 138
Registered: December 2014
Location: India
Senior Member
Hallo

I would like to thank you all for your suggestion n feedback.. its also hard for me to clear you.. sry i could not make you more clear...

i would like to close this thread here and i will try it somehow.. Sad
Re: EXISTS SQL QUERY [message #635078 is a reply to message #635077] Thu, 19 March 2015 14:48 Go to previous message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

The question is "is that clear for you?"

Previous Topic: need query based on the below requirement
Next Topic: REGEXP_REPLACE Help NEEDED....
Goto Forum:
  


Current Time: Tue Apr 23 09:27:26 CDT 2024