Results 1 to 4 of 4

Thread: combine queries

  1. #1
    Join Date
    May 2012
    Posts
    3

    Unanswered: combine queries

    i have two queries.query1 contans 25 multiple choice questions which are randomly generated from table of 103 records.query 2 contains true/false question randomly generated from table.i wish to merge two queries into one after other as follows and also number each records because questionnumber is showing random numbers.

    query1
    qno qdesc opta optb optc optd
    25 dfdsfdf a b c d
    ....

    query2
    qno qdesc opta optb
    6 cxcxz true false


    i wish to have result as follows
    qno qdesc opta optb optc optd
    1 fsdfdf a b c d
    2 dfdsf a b c d
    3 dfsdf a b c d
    ....25 records
    26 dfdsf true false



    please help

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Strictly speaking, you can't: a rowset cannot have a variable number of columns.

    Whant you can do is:
    Code:
    SELECT qno, qdesc, opta, optb, optc, optd
    FROM <TableA>
    UNION
    SELECT qno, qdesc, opta, optb, Null, Null
    FROM <TableB>
    Have a nice day!

  3. #3
    Join Date
    May 2012
    Posts
    3
    thanks for reply
    it works.i have to select from two queries where records are in random order.this query works but it shows the random records in ascending order whereas in query it shows in random order eg:

    query1:
    qno qdesc opta optb optc optd
    4 dasd d s d f
    2 sada h j k k
    7 sadsa t g r d

    query6:
    qno qdesc opta optb
    4 dasd d s
    6 sdsa f g
    1 sd r y


    after
    union
    qno qdesc opta optb optc optd
    2 sada h j k k
    4 dasd d s d f
    7 sadsa t g r d
    1 sd r y
    4 dasd d s
    6 sdsa f g

    i have to number it even

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You can alway issuer an ORDER BY clause:
    Code:
    SELECT qno, qdesc, opta, optb, optc, optd FROM query1
    UNION
    SELECT qno, qdesc, opta, optb, Null, Null FROM query6
    ORDER BY qno;
    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
  •