Results 1 to 3 of 3

Thread: Need Query Help

  1. #1
    Join Date
    Feb 2003
    Location
    In your thoughts
    Posts
    195

    Unanswered: Need Query Help

    I need to be able to create a query that will pull information from two tables. Here is the Table Structures:

    Code:
    RT TABLE
    RT_IMKEY          RT_WCKEY          RT_SEQNUM
    ------------         --------------         --------------
    JEREMY              SLEEP                 31234698734563
    JEREMY              WAKE                 32456478920499
    JEREMY              WORK OUT          33123456453328
    
    
    PS TABLE
    PS_IMKEY          PS_CPKEY           PS_SEQNUM
    ------------         -------------          ---------------
    JEREMY             EYE                     48574392938475
    JEREMY             NOSE                  46352435798097
    JEREMY             MOUTH                48757698490438
    What I need to do is create a query that will collect all of this information, and sort all records by the RT_SEQNUM AND PS_SEQNUM. I basically want all records sorted by sequence number and each items sequense number is (PS_SEQNUM) from the PS Table and (RT_SEQNUM) from the RT Table. Can someone help? Thanks, Jeremy
    Nothing better than a good ride.

  2. #2
    Join Date
    Apr 2003
    Posts
    3
    insert all data from both tables into a new table and query the new table with order by.
    if the keys from the first table all start with a 3 and from the second with a 4 you can make two select statements with order by and connect them both with a union statement

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Need Query Help

    Originally posted by JCScoobyRS
    I need to be able to create a query that will pull information from two tables. Here is the Table Structures:

    Code:
    RT TABLE
    RT_IMKEY          RT_WCKEY          RT_SEQNUM
    ------------         --------------         --------------
    JEREMY              SLEEP                 31234698734563
    JEREMY              WAKE                 32456478920499
    JEREMY              WORK OUT          33123456453328
    
    
    PS TABLE
    PS_IMKEY          PS_CPKEY           PS_SEQNUM
    ------------         -------------          ---------------
    JEREMY             EYE                     48574392938475
    JEREMY             NOSE                  46352435798097
    JEREMY             MOUTH                48757698490438
    What I need to do is create a query that will collect all of this information, and sort all records by the RT_SEQNUM AND PS_SEQNUM. I basically want all records sorted by sequence number and each items sequense number is (PS_SEQNUM) from the PS Table and (RT_SEQNUM) from the RT Table. Can someone help? Thanks, Jeremy
    If the result you want is:

    JEREMY SLEEP 31234698734563
    JEREMY WAKE 32456478920499
    JEREMY WORK OUT 33123456453328
    JEREMY NOSE 46352435798097
    JEREMY EYE 48574392938475
    JEREMY MOUTH 48757698490438

    ...then you can use UNION ALL:

    select RT_IMKEY, RT_WCKEY, RT_SEQNUM
    from RT_TABLE
    UNION ALL
    select PS_IMKEY, PS_CPKEY, PS_SEQNUM
    from PS_TABLE
    ORDER BY 3

Posting Permissions

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