Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Posts
    52

    Question Unanswered: Query union question

    Hi all friends:

    I have this two tables:


    Table 1

    idtable description moreFields
    ------- ------------ ------------
    1 Michael data1
    2 George data2
    3 Lucas data3
    4 Theodore data4
    5 Simon data5


    Table2
    idtable description moreFields
    ------ ------------ -----------
    1 Laura data1
    2 Lucia data2
    1 Laura data3
    3 Stephanie data4
    2 Lucia data5
    4 Kimberly data6
    5 Karla data7
    4 Kimberly data8
    5 Karla data9
    1 Laura data10
    2 Lucia data11
    3 Stephanie data12


    Im making this query

    SELECT
    *
    FROM
    TABLE1
    UNION
    SELECT
    *
    FROM
    TABLE2

    So i want to order the result of this query such as I get



    idtable description moreFields
    ------- ------------ ------------
    1 Michael data1
    1 Laura data1
    1 Laura data3
    1 Laura data10
    2 George data2
    2 Lucia data2
    2 Lucia data5
    2 Lucia data11
    3 Lucas data3
    3 Stephanie data4
    3 Stephanie data12
    4 Theodore data4
    4 Kimberly data6
    4 Kimberly data8
    5 Simon data5
    5 Karla data7
    5 Karla data9



    I mean the result is ordered by idtable of the union of the two tables.

    I will thank any helpany suggestion, any idea!!!


    Regards!!!

  2. #2
    Join Date
    Nov 2003
    Posts
    39

    Re: Query union question

    just use order by on idtable column
    here is the example

    SQL> select * from r1 ;
    ID NAME
    ---------- ----------
    1 tom
    3 ram

    SQL> select * from r2 ;
    ID NAME
    ---------- ----------
    2 john


    SQL> select ID, NAME from r1 union select ID, NAME from r2 order by id ;

    ID NAME
    ---------- ----------
    1 tom
    2 john
    3 ram


    Originally posted by quetzalcoatl
    Hi all friends:

    I have this two tables:


    Table 1

    idtable description moreFields
    ------- ------------ ------------
    1 Michael data1
    2 George data2
    3 Lucas data3
    4 Theodore data4
    5 Simon data5


    Table2
    idtable description moreFields
    ------ ------------ -----------
    1 Laura data1
    2 Lucia data2
    1 Laura data3
    3 Stephanie data4
    2 Lucia data5
    4 Kimberly data6
    5 Karla data7
    4 Kimberly data8
    5 Karla data9
    1 Laura data10
    2 Lucia data11
    3 Stephanie data12


    Im making this query

    SELECT
    *
    FROM
    TABLE1
    UNION
    SELECT
    *
    FROM
    TABLE2

    So i want to order the result of this query such as I get



    idtable description moreFields
    ------- ------------ ------------
    1 Michael data1
    1 Laura data1
    1 Laura data3
    1 Laura data10
    2 George data2
    2 Lucia data2
    2 Lucia data5
    2 Lucia data11
    3 Lucas data3
    3 Stephanie data4
    3 Stephanie data12
    4 Theodore data4
    4 Kimberly data6
    4 Kimberly data8
    5 Simon data5
    5 Karla data7
    5 Karla data9



    I mean the result is ordered by idtable of the union of the two tables.

    I will thank any helpany suggestion, any idea!!!


    Regards!!!

Posting Permissions

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