Discussions
Categories
- 196.8K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 544 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.9K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.5K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 439 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
Need help for an SQL statement, where we want to see all shipments where no rooskens_enity is presen

We want to create a query that checks whether a shipment has a Rooskens enity.
The queries should show all shipments that do not have a Rooskens entity. To create this queries we need to use 2 tables namely:
SHIPMENT and SHIPMENT_REFNUM
The difficulty for us is that in SHIPMENT_REFNUM are about 10 records of 1 shipment (see example data)
TABLE (SHIPMENT)
Example data: (fieldname SHIPMENT_GID)
SHIPMENT_123
SHIPMENT_1234
table (SHIPMENT_REFNUM)
Sample data (field names: SHIPMENT_GID, SHIPMENT_REFNUM_QUAL_GID)
SHIPMENT_123, ROOSKENS_ENTITY
SHIPMENT_123, GLOG
SHIPMENT_123, PAYMENT_TERM
SHIPMENT_123, LOADING_METERS
SHIPMENT_123, LICENSE_PLATE
SHIPMENT_123, REVENUE_PERCENTAGE
SHIPMENT_1234, GLOG
SHIPMENT_1234, PAYMENT_TERM
SHIPMENT_1234, LOADING_METERS
SHIPMENT_1234, LICENSE_PLATE
SHIPMENT_1234, REVENUE_PERCENTAGE
Based on this data it is visible that SHIPMENT_GID has no ROOSKENS_ENITY. We want to get this shipment back. It is important for the program that the select statement only contains SHIPMENT_GID from the table SHIPMENT.
I would like your help with this.
Thanks in advance.
Best Answer
-
Unless I'm missing something, a simple (NOT) EXISTS predicate should do just fine :
select sh.shipment_gid from shipment sh where not exists ( select null from shipment_refnum sr where sr.shipment_gid = sh.shipment_gid and sr.shipment_refnum_qual_gid = 'ROOSKENS_ENTITY' );
Answers
-
Here's one way.
SQL> with shipment(SHIPMENT_GID) as ( 2 select 'SHIPMENT_123' from dual union all 3 select 'SHIPMENT_1234' from dual 4 ) 5 ,shipment_refnum(shipment_gid, shipment_refnum_qual_gid) as ( 6 select 'SHIPMENT_123', 'ROOSKENS_ENTITY' from dual union all 7 select 'SHIPMENT_123', 'GLOG' from dual union all 8 select 'SHIPMENT_123', 'PAYMENT_TERM' from dual union all 9 select 'SHIPMENT_123', 'LOADING_METERS' from dual union all 10 select 'SHIPMENT_123', 'LICENSE_PLATE' from dual union all 11 select 'SHIPMENT_123', 'REVENUE_PERCENTAGE' from dual union all 12 select 'SHIPMENT_1234', 'GLOG' from dual union all 13 select 'SHIPMENT_1234', 'PAYMENT_TERM' from dual union all 14 select 'SHIPMENT_1234', 'LOADING_METERS' from dual union all 15 select 'SHIPMENT_1234', 'LICENSE_PLATE' from dual union all 16 select 'SHIPMENT_1234', 'REVENUE_PERCENTAGE' from dual 17 ) 18 select shipment_gid 19 from shipment s 20 minus 21 select shipment_gid 22 from shipment_refnum 23 where shipment_refnum_qual_gid = 'ROOSKENS_ENTITY' 24 / SHIPMENT_GID ------------- SHIPMENT_1234
If that's not what you wanted, then please post details of your expected results. You should also specify your database version as different versions have different capabilities.
And it helps us if you post your data in a format we can create easily on our own databases, so that we can easily help you, rather than each person having to try and take your question and format your data into usable tables.
-
Unless I'm missing something, a simple (NOT) EXISTS predicate should do just fine :
select sh.shipment_gid from shipment sh where not exists ( select null from shipment_refnum sr where sr.shipment_gid = sh.shipment_gid and sr.shipment_refnum_qual_gid = 'ROOSKENS_ENTITY' );
-