Query help
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Query help

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1

    Query help

    ok I am through pulling my hair out and decided to let you guys help me .

    I have 2 tables
    Table 1
    ID - Container - internalid
    100 A01001 1
    101 A01002 3
    102 A01003 2
    103 A01001 4
    104 A01003 5

    Table 2
    ID Container ShortName
    1 A01001 A01
    2 A01002 A01
    3 A01003 A01

    My problem is this
    1 - I start with the internal id of 1
    2 - I need ot find the only container in table 1 with 1 record

    Expected output = 102

    My attempts have been
    select
    id, container
    from
    table 1
    where
    substr(container,1,9) in
    (
    select substr(container,1,9)
    from table 1
    where ID in (1)
    ) and
    having count(container) = 1
    group by id, container -- I really don't want to group here, but have to and this screws up the query
    order by container


    Thanks in advance

  2. #2
    Join Date
    Feb 2013
    Posts
    8
    I have some question based on this :
    1)Do you want only records from Table1, which have no repetitive container like 'A01002'
    2)The select query doesn't contain Table2, so what exact query should be only table1

    If you want non repetitive container from table1 then use below query
    select count(Container ), Container from table 1
    group by Container
    having count(Container ) = 1

    Do reply on the above 2 points and whether this will suffix your problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width