Solved

SQL - Query Location table where ADDR1 have duplicated values

Posted on 2013-06-19
3
546 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 69

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sql Stored Procedure field variable 17 31
run sql script from putty 4 37
SELECT query on two levels (detail and summary) 13 50
Oracle encryption 12 34
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

832 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