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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:23:52+00:00 2026-06-02T05:23:52+00:00

I’m trying to write a SQL statement to find all of the rows in

  • 0

I’m trying to write a SQL statement to find all of the rows in a table that, for one field, contain the same values. However I only want to return the rows that have different values for a separate attribute. This is a little hard to explain.

I have a table Teacher with the schema:

TeacherName varchar(50)
CourseN     int
Quarter     varchar(50)

The three fields combined make up the primary key, so the same teacher can teach the same course so long as the quarter is different. The problem I’m trying to solve is, how can I return the (distinct) names of all the teachers who teach at least two different courses (regardless of quarter)?

This is for a lab and I’ve been trying to solve this problem for about a week and I just cannot figure it out, so I figured I would come here. The previous question asked to find the distinct list of names of teachers who teach the same course at least twice. I came up with this:

SELECT DISTINCT [TeacherName] 
FROM            [Teacher]
GROUP BY        [TeacherName], 
                [CourseN] 
HAVING   COUNT( [CourseN] ) >= 2

However the problem I’m trying to solve now is similar, but again, I need only teachers who show up in the table more than once that teach at least two different courses. I would really appreciate some guidance as well, rather than just the answer, since it’s important that I understand exactly what the database is doing.

  • 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-02T05:23:55+00:00Added an answer on June 2, 2026 at 5:23 am

    You should be able to get the distinct list without having to use the word DISTINCT in this case, particularly if it can be “regardless of quarter”. Essentially, you just want the teachers who have >=2 rows in the subquery table that has 1 row per unique teacher-coursenumber combination.

    select TeacherName
    from (
        select TeacherName, CourseN
        from Teacher
        group by TeacherName, CourseN
        ) t1
    group by TeacherName
    having count(*) >=2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

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.