Home » SQL & PL/SQL » SQL & PL/SQL » SQL query (merged 3)
SQL query (merged 3) [message #635294] Thu, 26 March 2015 07:40 Go to next message
sunny1234
Messages: 4
Registered: March 2015
Junior Member
I have a customer table and transaction table. I want to display all the customer id from Transaction table only if the ShipmentStatus ='Yes'. If any record for ShipmentStatus = NO, I want to exclude all the records for that customer ID. How do i write a query to search in this case?

Customer table:
Customer ID, Order date, Item
1234
2345
6677

Transaction Table:
Customer ID, Transaction ID, ShipmentStatus
1234 45566 Yes
1234 78787 No
1234 55788 Yes
6677 46777 Yes
6677 54666 Yes
Re: SQL query [message #635296 is a reply to message #635294] Thu, 26 March 2015 07:46 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Welcome to the forum. Please read our OraFAQ Forum Guide and How to use [code] tags and make your code easier to read

As for your question, you need to start by providing the two CREATE TABLE statements that you used and the eight INSERT statements. Without them, no-one can reproduce your case.
Re: SQL query [message #635300 is a reply to message #635296] Thu, 26 March 2015 08:21 Go to previous messageGo to next message
sunny1234
Messages: 4
Registered: March 2015
Junior Member
Thanks. But this is just a sample. There is no issue. I just need a guidance to write the query
Re: SQL query [message #635303 is a reply to message #635300] Thu, 26 March 2015 08:25 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Use SELECT and NOT EXISTS, for instance.

Re: SQL query [message #635316 is a reply to message #635300] Thu, 26 March 2015 10:46 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Analytic function, e.g. COUNT.

SY.
Re: SQL query [message #635329 is a reply to message #635316] Fri, 27 March 2015 00:35 Go to previous messageGo to next message
sunny1234
Messages: 4
Registered: March 2015
Junior Member
How would cont help? I want to display the customers ids only if there, all shipments status ='Yes' if any of the transactions are No thn exclude the customer id.
In the above data sample, Only 6677 customer id should be displayed.
Re: SQL query [message #635330 is a reply to message #635329] Fri, 27 March 2015 01:23 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You said:

Quote:
I just need a guidance to write the query

We did.

Now if you want more then read and follow the links John gave you.
To be more specific:
With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Also always post your Oracle version, with 4 decimals.

Now maybe you could show us what you tried and tell us where you are stuck and we may help you to go further.

[Updated on: Fri, 27 March 2015 01:32]

Report message to a moderator

Re: SQL query [message #635331 is a reply to message #635329] Fri, 27 March 2015 01:43 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
sunny1234

How would count help?

A straightforward option would be the following: count number of ALL records and compare it with a number of YES records. If they match, display the ID.
Re: SQL query [message #635334 is a reply to message #635300] Fri, 27 March 2015 02:37 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
sunny1234 wrote on Thu, 26 March 2015 13:21
Thanks. But this is just a sample. There is no issue. I just need a guidance to write the query
I hve a couple of ideas, but without the tbles I can't try them out.
Re: SQL query [message #635336 is a reply to message #635329] Fri, 27 March 2015 02:54 Go to previous messageGo to next message
sunny1234
Messages: 4
Registered: March 2015
Junior Member
Sorry, i missed to add some more information.. Table structure is changed now.

Order table:
Order No, Order date, ItemStatus
1234 , 01-01-2014 Hold
4567 , 01-31-2013, Sent
6677, 02-02-2015, Hold


Transaction Table:
Order No, Item No, ShipmentStatus
1234 45566 Yes
1234 54345 Yes
1234 95586 Yes

4567 78787 Yes
4567 55788 Yes

6677 46777 No
6677 54666 Yes

In order table, each Order number can have multiple items placed which is in transaction table.
For eg. Order no. 1234 in Transaction table all item no are shipped and in order table Item status is still Hold for 1234. It's not updated. I want to query all the records for order no which is in hold status and Shipment Status is Yes.
Re: SQL query [message #635338 is a reply to message #635336] Fri, 27 March 2015 02:56 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You missed far more than that, you missed to read the links and posts and post accordingly.

If you despise us how could you expect we help you?

[Updated on: Fri, 27 March 2015 02:59]

Report message to a moderator

Re: SQL query [message #635340 is a reply to message #635336] Fri, 27 March 2015 02:58 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Sunny, you will never make any success in your professional life if you ignore all suggestions from people who would like to assist you. Put yoursef in my position: would you bother to spend any more time trying to help someone as deliberately uncooperative as you?

I suggest that you close this topic, with big thankyou to everyone who took time to reply, and start another. This time read the forum guidelines, and do it properly.
Re: Query help [message #635341 is a reply to message #635294] Fri, 27 March 2015 03:01 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Stop flooding our site with the same question and posts which don't follow our guidelines.

Re: SQL query [message #635352 is a reply to message #635329] Fri, 27 March 2015 06:21 Go to previous message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
You use analytic COUNT to count ShipmentStatus = NO per customer and then select rows where such count is zero.

SY.
Previous Topic: Converting Prompt syntax into regular sql
Next Topic: Query regarding Outer Join
Goto Forum:
  


Current Time: Thu Apr 25 03:23:37 CDT 2024