Solved

SQL - Query Location table where ADDR1 have duplicated values

Posted on 2013-06-19
3
543 Views
Last Modified: 2013-06-19
Hello all

I'm trying to extract from my LOCATION table all locations that have duplicated values in column ADDR1 field but using the SQL below.

But i have this error: ORA-00933: SQL command not properly ended

How can i fix this?

Thanks again for your help.


SELECT CNT, 
    'L' AS L,
         'M' AS M,
         ID,
         DECODE (LOC_TYPE_ID,
                 0,
                 'PLAN',
                 1,
                 'CUSTOMER',
                 2,
                 'VENDOR',
                 3,
                 'DIST',
                 5,
                 'CROSSDOCK')
            AS LOC_TYPE_ID,
         NAME,
         ADDR1,
         ADDR2,
         CITY,
         STATE,
         COUNTRY,
         ZIP,
         CONTACT,
         PHONE,
         PHONE_SPD,
         FAX,
         LATITUDE,
         LONGITUDE,
         ZONE,
         PU_STOPTM,
         DEL_STOPTM,
         APPOINTMENT_REQUIRED,
         TIME_ZONE_ID,
         LOAD_CLASS_ID,
         CONSOLIDATION_ALLOWED,
         PARCEL_SERVICE,
         LOCATION_GROUP,
         MAX_CROSSDOCK_DAYS,
         PARCEL_CARRIER,
         ALT_LOCATION_ID,
         LOC_ROUTING_CLASS_ID,
         PICK_SRV_CLASS_ID,
         DELV_SRV_CLASS_ID,
         SPLC,
         APPOINTMENT_HONORED,
         SPLIT_WEIGHT,
         SPLIT_CUBE,
         SPLIT_PALLET,
         SPLIT_PIECES,
         SET_ID,
         SHIP_PRIORITY_ID,
         EMAIL,
         TRADE_AREA,
         SCNALIAS,
         XDOCK_HANDLING_TIME,
         SHPPTY,
         XDOCK_LIVE_LOADING,
         OWNER,
         PORT_CODE,
         NOTES
  FROM   LOCATION
(
SELECT COUNT(*) CNT,
    ADDR1
FROM 
      LOCATION
-GROUP BY ADDR1
HAVING COUNT > 1; 

Open in new window

0
Comment
Question by:Wilder1626
3 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
ID: 39259556
The syntax error is due to a missing ')'

Try this one:
select * from 
(
SELECT CNT, 
    'L' AS L,
         'M' AS M,
         ID,
         DECODE (LOC_TYPE_ID,
                 0,
                 'PLAN',
                 1,
                 'CUSTOMER',
                 2,
                 'VENDOR',
                 3,
                 'DIST',
                 5,
                 'CROSSDOCK')
            AS LOC_TYPE_ID,
         NAME,
         ADDR1,
         ADDR2,
         CITY,
         STATE,
         COUNTRY,
         ZIP,
         CONTACT,
         PHONE,
         PHONE_SPD,
         FAX,
         LATITUDE,
         LONGITUDE,
         ZONE,
         PU_STOPTM,
         DEL_STOPTM,
         APPOINTMENT_REQUIRED,
         TIME_ZONE_ID,
         LOAD_CLASS_ID,
         CONSOLIDATION_ALLOWED,
         PARCEL_SERVICE,
         LOCATION_GROUP,
         MAX_CROSSDOCK_DAYS,
         PARCEL_CARRIER,
         ALT_LOCATION_ID,
         LOC_ROUTING_CLASS_ID,
         PICK_SRV_CLASS_ID,
         DELV_SRV_CLASS_ID,
         SPLC,
         APPOINTMENT_HONORED,
         SPLIT_WEIGHT,
         SPLIT_CUBE,
         SPLIT_PALLET,
         SPLIT_PIECES,
         SET_ID,
         SHIP_PRIORITY_ID,
         EMAIL,
         TRADE_AREA,
         SCNALIAS,
         XDOCK_HANDLING_TIME,
         SHPPTY,
         XDOCK_LIVE_LOADING,
         OWNER,
         PORT_CODE,
         NOTES,
	count(*) over(partition by addr1 order by addr1) addr1_count
  FROM   LOCATION
)
where addr1_count > 1
; 

Open in new window

0
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 250 total points
ID: 39259558
Select
....
from Location join (
SELECT COUNT(*) CNT,
    ADDR1
FROM 
      LOCATION
GROUP BY ADDR1
HAVING COUNT > 1) cnt
on location.addr1 = cnt.addr1;

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39260252
Many thanks, now it work great
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to recover a database from a user managed backup

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now