Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7659573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:21:02+00:00 2026-05-31T13:21:02+00:00

hi Programmers! I have to compare the select query between union query My code

  • 0

hi Programmers!
I have to compare the select query between union query

My code goes like this:

           select emp_id,type from
           (
               select emp_id,'leave' as type 
                 from tbl_emp_info 
                where emp_id like'5_2' or emp_id like '602' 
           ) as t1
           union 
           select emp_id,type from
           (
               select emp_id,'weekend'as type 
                 from tbl_emp_off_info 
                where emp_id like'6_2' 
           ) t2 t1.emp_id!=t2.emp_id

I need to compare these two select query

      As i need the result like

          EMP_ID      TYPE

          512        leave
          612       weekend            

But not like

          EMP_ID      TYPE


          512        leave
          612        leave
          612       weekend            

Please help me out

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:21:02+00:00Added an answer on May 31, 2026 at 1:21 pm

    Perhaps this will work for you (SQL Server 2005 and up).

    ;WITH t1 AS
    (
        SELECT emp_id, 'leave' AS [type]
        FROM tbl_emp_info 
        WHERE emp_id LIKE '5_2' OR emp_id LIKE '602'
    )
    , t2 AS
    (
        SELECT emp_id, 'weekend' AS [type]
        FROM tbl_emp_info 
        WHERE emp_id LIKE '6_2'
    )
    SELECT emp_id, [type]
    FROM t1
    WHERE emp_id NOT IN (SELECT emp_id FROM t2)
    UNION
    SELECT emp_id, [type]
    FROM t2
    

    For SQL Server 2000 you’ll need to duplicate one of the WHERE clauses:

    SELECT emp_id, 'leave' AS [type]
    FROM tbl_emp_info 
    WHERE (emp_id LIKE '5_2' OR emp_id LIKE '602')
    AND NOT (emp_id LIKE '6_2')
    UNION 
    SELECT emp_id, 'weekend' AS [type]
    FROM tbl_emp_info 
    WHERE (emp_id LIKE '6_2')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Even experienced programmers write C# code like this sometimes: double x = 2.5; double
How do Window's programmers profile their native C++ code? On Unix/Linux you have gprof
This question is for experiences programmers. Do you have a set process that you
I have a table which is full of arbitrarily formatted phone numbers, like this
Many C++ programmers have suffered from the fierce clashes with the global C++ objects
Let's say I have programmers and artists working on a project. The artists have
In the past I've worked with a number of programmers who have worked exclusively
I have multiple programmers contributing examples for javadocs and some examples contain comments formatted
We have a large number of programmers on different platforms all using CVS. We
I have often wondered why it is that non-English speaking programmers are forced to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.