Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2004
    Posts
    40

    Unanswered: query union .. help.

    i have 2 same table(same fields name) but different information.
    each table have same fields name, but the problem is query return result is different, for etc,

    my another table class, two 2 field, (Class IN(PK)) and (Name of Class)

    i do the union command ,for i want to get information of NAME OF CLASS from both table.

    but it return CLASS IN information instead. why is it so?

    select [Class IN],
    from [table 1]

    union select [Class IN]
    from [table 2];

    but i do another Staff in , name of staff
    it does return the name of staff in display correctly. but not class, why is it so? please help

  2. #2
    Join Date
    Jun 2004
    Posts
    92
    Quote Originally Posted by xeroleacy
    i do the union command ,for i want to get information of NAME OF CLASS from both table.
    If you wanted name of class why wouldn't you do:

    Code:
    select [name of class],
    from [table1]
    
    union select [name of class],
    from [table2];

  3. #3
    Join Date
    Jun 2004
    Posts
    40
    yes, i have tried that code, it work. but the problem is, i have few main fields, sub field , for etc, main field is Class IN, sub field is Name of Class,

    the real problem is,

    select [Class IN], [Staff IN], [ No of student], go on...
    from [table1]
    union
    select [Class IN], [Staff IN], [ No of student], go on...
    from [table2]

    i cant simply write like that,
    select [class in],[Name of class], [Staff in], [No of student] ......... ??

    before the problem , it does return the name of staff without writing the code "[Staff IN], [Name of Staff ]" but not [Class IN] code.

    why...? i cant find way to fix the problem. it seem too identically.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    perhaps you want UNION ALL instead of UNION
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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