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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:41:27+00:00 2026-06-13T14:41:27+00:00

I have been asked to create a query for this on a simple employee

  • 0

I have been asked to create a query for this on a simple employee database columns include:

ninumber – first name – last name – address – SuperVisorNiNumber

The employees and supervisors are all held in the same table and are referenced by their ninumbers. The query I’ve been asked to build is:

v. Find the NI Numbers, first and last names of employees and NI numbers of supervisors where the employees share that supervisor and both employees and supervisors work in department 8. You will refer to the employee relation twice was done in query vi of Practical 2. Your results should be presented in columns with the following titles ‘Employee NI number’, ‘First Name’, ‘Last Name’ and ‘Supervisor NI Number’.

Therefore I created this query:

SELECT e1.ninumber,
       e1.fname,
       e1.minit,
       e1.lname,
       e1.address,
       e1.superNiNumber,
       COUNT(*) AS nrOfOccurences
FROM   employee AS e1,
       employee AS e2
WHERE  e1.dno = 8
   AND e1.superNiNumber = e2.ninumber
   AND e2.dno = 8
GROUP  BY e1.superNiNumber
HAVING COUNT(*) > 1

I couldn’t do a not distinct query to work out this part of the question – “where the employees share that supervisor”. This query returns a grouping of the rows which in turn hides some of the rows I want to show.

My question is: Is my query correct for the question and can I do a NON DISTINCT query in mySQL to get the database to return all of the fields instead of grouping them together.

Reutrn results from my query

NInumber    fname  minit    lname   address    supervisorNiNum     number of occerences
666666601   Jill    J   Jarvis  6234 Lincoln, Antrim, UK    666666600   2
666666607   Gerald  D   Small   122 Ball Street, Letterkenny, IRL   666666602   3
666666604   Billie  J   King    556 WAshington, Antrim, UK  666666603   2

Thanks.

  • 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-13T14:41:28+00:00Added an answer on June 13, 2026 at 2:41 pm

    In your result table column description, I see no minit, address and number of occurrences. Therefore I would simplify your select to:

    SELECT e1.ninumber,
           e1.fname,
           e1.lname,
           e1.superNiNumber,
    FROM   employee AS e1,
           employee AS e2
    WHERE  e1.dno = 8
           AND e1.superNiNumber = e2.ninumber
           AND e2.dno = 8
           and (select count(*) from employee e3
                where e3.superNiNumber = e1.superNiNumber) > 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to web programming...I have been asked to create a simple Internet
I have been asked to create a graphical representation of our database, I have
The basics of this query have been asked, and answered, many times before, but
I have been asked to create some functionality in which marketing team send users
I have been asked to create a vbscript that will set the default font
For a project I am working on, I have been asked to create an
Various incarnations of this question have been asked here before, but I thought I'd
I know this has been asked before. But I have exhausted the options given
I'm new to Java and have been asked to create an applet/servlet (not sure
I haven't touched PHP in years and have been asked to create an wordpress

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.