Solved

SQL - Query Location table where ADDR1 have duplicated values

Posted on 2013-06-19
3
548 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 77

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 70

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
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.​
Via a live example, show how to take different types of Oracle backups using RMAN.
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

737 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