Results 1 to 8 of 8

Thread: Sql query

  1. #1
    Join Date
    Jul 2004
    Posts
    102

    Unanswered: Sql query

    Hi all,

    I have two tables

    Table a contain data :

    D001 25000
    D001 15000

    Table b contain data :

    D001 35000
    D002 20000

    Now i need data from those two table

    D001 25000
    D001 15000
    D002 20000

    Is that possible. If possible then provire the code.

    Thanks in advance for your help.

    Momin
    Working Together...

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    select * from a
    union
    select * from b
    where first_column <> 'D001';

  3. #3
    Join Date
    Jul 2004
    Posts
    102
    Thanks Littlefoot

    I send a example. I have more than 1000 records each table and i cannot specify first_column value. then what is the query ?
    Working Together...

  4. #4
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    My query is also an example ... and, regarding YOUR example, you took all records from table A and only the D002 record from table B. I really wouldn't know your real situation; if you need to join all records from one and another table, then use simply
    SELECT * FROM a UNION SELECT * FROM b;
    Or, if you have conditions to meet, include them into the WHERE clause(s).

  5. #5
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    Momin,

    Certainly if you explained your needs more clearly it would be much easier for us to help you, don't you think ?

    With the few info you gave so far, we can't do more than Littlefoot already did.

    As some other people would say, we're not "mind-readers" (sorry for that, no crystal ball here ).

    Regards,

    RBARAER

  6. #6
    Join Date
    Aug 2004
    Posts
    330
    This could also work:

    select
    'D001', 25000
    from DUAL
    union
    select
    'D001', 15000
    from DUAL
    union
    select
    'D002', 20000
    from DUAL;

  7. #7
    Join Date
    Jan 2004
    Posts
    492
    In theory yes that would work, but I'm willing to bet dollars to donuts that his tables contain a couple more rows. So dual would literally give you those 3 rows, but I think he is looking more for a pattern to grab unrelated data from 2 tables.

    But as others post, since little detail is given, its all just speculamation.
    Oracle OCPI (Certified Practicing Idiot)

  8. #8
    Join Date
    May 2004
    Location
    Dominican Republic
    Posts
    721
    Perhaps he/she is only looking for the 'long running' of each table's col1..
    Code:
    SQL@8i> select t, col1, col2
      2    from (
      3  select t.*,
      4         max( cnt ) over( partition by col1 ) mx
      5    from (
      6  select 'A' t,
      7         count( * ) over( partition by a.col1 ) cnt,
      8         a.*
      9    from a
     10  union all
     11  select 'B' t,
     12         count( * ) over( partition by b.col1 ) cnt,
     13         b.*
     14    from b
     15         ) t
     16         )
     17   where mx = cnt
     18  /
    
    T COL1      COL2
    - ---- ---------
    A D001     25000
    A D001     15000
    B D002     20000
    
    SQL@8i>
    or perhaps he/she is looking for something else.. who knows..

Posting Permissions

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