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

  • SEARCH
  • Home
  • 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 8975683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:56:31+00:00 2026-06-15T18:56:31+00:00

I have two tables empmaster and allocation . I used union to do sql

  • 0

I have two tables empmaster and allocation. I used union to do sql operation in order to get results from two tables. empmaster has empid and other empdetails. Table allocation contains empid from empmaster as foriegn key another field called per_alloc. I need to retrieve empdetails which satisfies:

  1. empmaster.empid not in allocation.empid.

  2. empmaster.empid in allocation.empid and allocation.per_alloc < 100.

MySQL query I used is:

  select distinct(tbl_empmaster.emp_fname) 
  from tbl_empmaster 
  where tbl_empmaster.emp_id not in(select tbl_allocation.emp_id 
                                    from tbl_allocation)
  union
  select distinct(tbl_empmaster.emp_fname) 
  from tbl_empmaster 
   where tbl_empmaster.emp_id in(select tbl_allocation.emp_id 
                                 from tbl_allocation  
                                 group by emp_id  
                                 having sum(per_alloc) < 100)

This only retrieves empdetails, say tbl_empmaster.emp_fname, I need to retrieve sum(per_alloc) from select tbl_allocation!!! When I tried it gives lot of errors, Can any one show me the correct way, please?

  • 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-06-15T18:56:33+00:00Added an answer on June 15, 2026 at 6:56 pm

    Try this:

    SELECT DISTINCT em.emp_fname, 0 alloc 
    FROM tbl_empmaster em
    WHERE em.emp_id NOT IN(SELECT emp_id FROM tbl_allocation)
    UNION
    SELECT DISTINCT em.emp_fname, SUM(a.per_alloc) alloc
    FROM tbl_empmaster em 
    INNER JOIN tbl_allocation a ON em.emp_id = a.emp_id 
    GROUP BY a.emp_id 
    HAVING SUM(a.per_alloc)<100
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables users and work_orders. Now I need to get work_orders results
I have two tables Order , OrderStatus . Order has OrderId (pk), OrderStatusId (fk)
I have two tables as shown below EmpMaster empid firstName lastName lstatus 1 Mark
I have two tables, orders and old_orders. Each table has some similar fields and
I have two tables Master Detail In the Master & Detail table I get
I have two tables that are joined together. A has many B Normally you
I have two tables, namely Price List (Table A) and Order Record (Table B)
I have two tables that are all the same, except one has a timestamp
I have two tables: A, B. I need to select all data from B.
I have two tables: Transactions and TransactionAgents. TransactionAgents has a foreign key to Transactions

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.