find all course id which is taken by at least two different students

by Vallie Leffler 8 min read

Then, you can use HAVING clause to filter out the students having atleast two unique courses subscribed to (which would be 1 and 3 in this case): SELECT student_name FROM your_table_name WHERE course_number IN (1,3) GROUP BY student_name HAVING COUNT (DISTINCT course_number) = 2

Full Answer

How to add a third set of courses to a course?

Each condition in the having clause counts the number of students taking the particular courses. The > 0 says that there is at least one. If you want to add a third or fourth set of courses, that is very easy by adding more conditions in the HAVING clause. Thanks for contributing an answer to Stack Overflow!

How to use course_number and count in the same dataset?

If you have a different dataset (say course_numbers 1,2,3) you can use course_number in (1,2,3) and COUNT (distinct course_number) = 3 and so on. Show activity on this post. You can approach this problem using conditional aggregation based filtering.

How do you count the number of students in a course?

Each condition in the having clause counts the number of students taking the particular courses. The > 0 says that there is at least one. If you want to add a third or fourth set of courses, that is very easy by adding more conditions in the HAVING clause.

How to filter out students with multiple courses subscribed to?

Firstly, get all the students who are either enrolled IN (..) course no (1, 3). Then, you can use HAVING clause to filter out the students having atleast two unique courses subscribed to (which would be 1 and 3 in this case):

How do you get names and marks of the top 3 students?

SELECT statement is used to get name and marks of top three students.SQL query is. SELECT Name, Marks FROM Student s1 where 3 <= (SELECT COUNT(*) FROM Students s2 WHERE s1.marks = s2.marks)SQL (Structured Query Language) ... Functions of SQL (Structured Query Language)

Which of the following query will find all unique students who have taken more than one course?

Q6) Which of the following query will find all the unique students who have taken more than one course? Option D would be a right option. This query will first apply self join on enrolled table and then it evaluate the condition e1. sid = e2.

How do you SELECT all data from student information table where name starts from the letter R?

How to select all data from student table starting the name from letter 'r'?A. SELECT * FROM student WHERE name LIKE 'r%';SELECT * FROM student WHERE name LIKE '%r%';SELECT * FROM student WHERE name LIKE '%r';SELECT * FROM student WHERE name LIKE '_r%';

What will be the query to display the courses in which number of students enrolled is more than 5?

To get the number of students who are registered for more than 5 courses you do this... SELECT COUNT(*) FROM REGISTRATION WHERE SEMESTER = 'GIVEN SEMESTER' GROUP BY CAMPUS, STUDENT_ID HAVING COUNT(*) > 5; You need to group by campus AND student id since student id is repeated for different campuses.

How do I get unique values from two tables in SQL?

Contents:Sample Select statement.Select with distinct on two columns.Select with distinct on three columns.Select with distinct on all columns of the first query.Select with distinct on multiple columns and order by clause.Count() function and select with distinct on multiple columns.

How do I find unique rows in SQL?

The SQL SELECT DISTINCT Statement The SELECT DISTINCT statement is used to return only distinct (different) values. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.

How will you retrieve all the data from the students table?

SELECT statements An SQL SELECT statement retrieves records from a database table according to clauses (for example, FROM and WHERE ) that specify criteria. The syntax is: SELECT column1, column2 FROM table1, table2 WHERE column2='value';

How do you SELECT all the records from a table named persons?

With SQL, how do you select all the records from a table named “Persons” where the value of the column “FirstName” ends with an “a”? Explanation: The SQL LIKE clause is used to compare a value to similar values using wildcard operators. 3.

Which statement is used to get all data from the students table whose name starts with P?

SELECT * FROM student WHERE name LIKE '%p';

How do I count the number of students in SQL?

SELECT COUNT(column_name) counts the non-null values of column in the table. The total number of STU_DEPT values in above table are 7 but one of them is null. Since count(column_name) counts non-null values of the given column, thus the output is 6.

What are the clauses that are used to find a set of male students from the students table sorted in descending order based on their roll number?

Order by clause is used with SELECT statement for arranging retrieved data in sorted order. The Order by clause by default sorts the retrieved data in ascending order. To sort the data in descending order DESC keyword is used with Order by clause.

Which of the command is used to Select all the students from city Pune?

Answer. Answer: Which of the Query is used to Select all the Students from City = "Pune".