Solved

SQL - Query Location table where ADDR1 have duplicated values

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
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

729 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