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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:30:19+00:00 2026-06-02T16:30:19+00:00

I have a question where I must find unique tuples in a table, where

  • 0

I have a question where I must find unique tuples in a table, where they have not ever been seen inside another table. I then must count those tuples and display the ones that occur more then 10 times. That is, there are some jobs that don’t require job staff, I am to find the jobs that have never ever required a job staff and has ran in terms more then 10 times.

create table JobStaff (
    Job         integer references Job(id),
    staff       integer references Staff(id),
    role        integer references JobRole(id),
    primary key (job,staff,role)
);

create table Job (
    id          integer, 
    branch      integer not null references Branches(id),
    term        integer not null references Terms(id),
    primary key (id)
);

Essentially my code exists as:

CREATE OR REPLACE VIEW example AS
SELECT * FROM Job
WHERE id NOT IN (SELECT DISTINCT jobid FROM JobStaff);

create or replace view exampleTwo as
select branch, count(*) as ct from example group by 1;

create or replace view sixThree as
select branch, ct from exampleTwo where ct > 30;

This seems to return two extra rows then the expected result. I asked my lecturer and he said that it’s because I’m counting courses that SOMETIMES

EDIT: this means, that for all the terms the job was available, there were no job staff assigned to it

EDIT2: expected output and what I get:

what i got:

 branch  | cou
---------+-----
    7973 |  34
    7978 |  31
    8386 |  33
    8387 |  32
    8446 |  32
    8447 |  32
    8448 |  31
   61397 |  31
   62438 |  32
   63689 |  31

expected:

 branch  | cou
---------+-----
    7973 |  34
    8387 |  32
    8446 |  32
    8447 |  32
    8448 |  31
   61397 |  31
   62438 |  32
   63689 |  31
  • 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-02T16:30:20+00:00Added an answer on June 2, 2026 at 4:30 pm

    You have to understand that SQL works in the way that you must know what you want before you can design the query.

    In your question you write that you are looking for jobs that are not in jobstuff but now that we have the answer here, its clear that you were looking for branches that are not in jobstuff. My advice to you is: Take you time to word (in your language, or in English but not in SQL) exactly what you want BEFORE trying to implement it. When you are more experienced that isn’t necessary always but for a beginner its the best way to learn SQL.

    The Solution:

    The thing here is that you don’t need views to cascade queries, you can just select from inner queries. Also to filter elements based on a computed value (like count) can be done by the having clause.

    The count(DISTINCT ...) causes duplicate entries to be only counted once, so if a Job is in a term twice, it now gets counted only once.

    The query below selects all branches that ever got a jobstaff and then looks for jobs that are not in this list.

    As far as I understood your question this should help you:

    SELECT branch, count(DISTINCT term_id) as cou
    FROM jobs j
    WHERE j.branch NOT IN (SELECT branch FROM job WHERE job.id IN (select jobid FROM jobstaff))
    GROUP BY branch
    HAVING count(DISTINCT term_id) > 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have tried to find a answer but must not be searching correctly
I know this question have been asked endless times but I can't find a
I know this is an old question and must have been answered hundred times
(second question today - must be a bad day) I have a dataframe with
I am sure that this kind of questions must have been asked before, but
Minimum Set Cover is a question where you must find the minimum number of
I am doing project euler question 63 where I must find the amount of
I feel stupid asking this question, but I can not find a clear answer
I have a question which I see from googling has been discussed at length..
I have a question that must be answer several times before, but I can't

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.