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 9170047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:57:47+00:00 2026-06-17T15:57:47+00:00

Here the SQL FIDDLE and below tabel schema with values. I want to select

  • 0

Here the
SQL FIDDLE and below tabel schema with values.
I want to select id_emp,fname_emp,TotalProject with a condition whose skillsid in (1,2).
Query i tried gives wrong output.

create table employee_emp(
id_emp int identity(1,1),fname_emp varchar(20),lname_emp varchar(20))
 insert into employee_emp values('John','Cena');
 insert into employee_emp values('Michel','shawn');
 insert into employee_emp values('Jay','mac');
 insert into employee_emp values('David','jackson');

create table skills_skl(
idemp_skl int,idskill_skl int
)
insert into skills_skl values(1,1);
insert into skills_skl values(1,2);
insert into skills_skl values(1,3);
insert into skills_skl values(1,4);
insert into skills_skl values(2,2);
insert into skills_skl values(2,3);
insert into skills_skl values(3,1);
insert into skills_skl values(3,4);
insert into skills_skl values(4,2);

create table employee_ejp(
id_ejp int identity(1,1),idemp_ejp int ,idproject_ejp int)
insert into employee_ejp values(1,1);
insert into employee_ejp values(1,2);
insert into employee_ejp values(1,3);
insert into employee_ejp values(2,3);
insert into employee_ejp values(2,2);
insert into employee_ejp values(3,1);
insert into employee_ejp values(4,4);

Query I tried

1)

select a.id_emp,a.fname_emp,count(b.id_ejp) TotalP from employee_emp a
join employee_ejp b on a.id_emp=b.idemp_ejp 
group by a.id_emp,a.fname_emp

2)

select a.id_emp,a.fname_emp,count(b.id_ejp) TotalP from employee_emp a
join employee_ejp b on a.id_emp=b.idemp_ejp join skills_skl c on c.idskill_skl=a.id_emp
where c.idskill_skl in (1,2)
group by a.id_emp,a.fname_emp
  • 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-17T15:57:47+00:00Added an answer on June 17, 2026 at 3:57 pm

    Here the easy approach:

    ;with emps_1_2 as (
    select distinct a.id_emp
      from employee_emp a
      join skills_skl c on c.idemp_skl=a.id_emp     --Be carefull here!
      where c.idskill_skl in (1,2)
    )  
    select emp.id_emp,
           emp.fname_emp,
           coalesce( COUNT(ejp.id_ejp), 0) as TotalProject 
    from       employee_emp emp 
    inner join emps_1_2 emp12 
            on emp.id_emp = emp12.id_emp
     left join employee_ejp ejp 
            on emp.id_emp=ejp.idemp_ejp
    group by emp.id_emp,emp.fname_emp
    

    Results:

    | ID_EMP | FNAME_EMP | TOTALPROJECT |
    -------------------------------------
    |      4 |     David |            1 |
    |      3 |       Jay |            1 |
    |      1 |      John |            3 |
    |      2 |    Michel |            2 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 4 MySQL Tables shown here: SQL Fiddle I need to select station
Here is a SQL query which fail if multiple values are returned by first-
here is the sql codes SELECT roles.role_id, usertype_module.role_id, usertype_module.viewable, usertype_module.editable, usertype_module.createable, modules.modules_id, usertype_module.modules_id, modules.modules,
I have this SQL code here.. SELECT cl.clientid, cl.clientname, cl.billingdate, cp.startdate, cp.expiration, (SELECT COUNT(*)
== SQL Fiddle of My Question Here I have the following tables related to
I have an sql fiddle here: http://www.sqlfiddle.com/#!2/fbd48/1 The colors should be red for flower
This question already has an answer here: view sql that linq-to-sql produces 3 Answers
I am new to SQL Server 2008 fill factor, as mentioned here in SQL
In the comments on this answer , Remou writes that CurrentDB.Execute insert sql here
Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id

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.