Results 1 to 4 of 4
  1. #1
    Join Date
    May 2012
    Posts
    132

    Unanswered: a combination query

    Query1 has one result like the following
    Code:
    ID   studentname    lectureplace       lecturesubject
    23        jack           A             Geography
    Query2 has results like the fowloing:
    Code:
    ID   studentname    lectureplace       lecturesubject
    12        jack           A             Biology    
    18        jack           c             politics    
    20        jack           B             math    
    22        jack           A             math    
    27        jack           B             math
    29        jack           A             math
    A table or query is required which has the record from query1 and those records from query2 whit ID greater than the ID of the record in query1. The following is what the result is like
    Code:
    ID   studentname    lectureplace       lecturesubject
    23        jack           A             Geography    
    27        jack           B             math
    29        jack           A             math
    Thank you
    Last edited by ariansman; 04-19-14 at 03:10.
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    I asked god to please give me everything to enjoy the life, God said: i gave you the life to enjoy everything.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    So use a subquery
    or do thid as a two separate queries
    or give us a clue as to how you select the data for query 1
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    May 2012
    Posts
    132
    Quote Originally Posted by healdem View Post
    So use a subquery
    or do thid as a two separate queries
    or give us a clue as to how you select the data for query 1
    thank you,
    there is a table of students lectures containing such fields: studentname, lecturedate, lecturesubject and lectureplace. ( i have not mentioned lecturedates here)
    i have made the query1 to show us the latest date when jack has performed a lecture on geography.
    query2 shows jack lectures on math.
    query3 must show the latest jack lecture on geography on the first row and all his math lectures presented after his lecture on geography shown on the first row.
    this really seems complicated to me. thank you for the instruction
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    I asked god to please give me everything to enjoy the life, God said: i gave you the life to enjoy everything.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If there is no other criteria you did not mentioned yet, you could use:
    Code:
    SELECT Query1.ID, Query1.studentname, Query1.lectureplace, Query1.lecturesubject
      FROM Query1
    UNION 
    SELECT Query2.ID, Query2.studentname, Query2.lectureplace, Query2.lecturesubject
      FROM Query2
     WHERE Query2.ID > (SELECT MAX(ID) FROM Query1)
    Have a nice day!

Posting Permissions

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