Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
Always Return Rows from Table A
Post Body

Apologies if this is duplicate, but failing to google or search here for an answer. I'm writing in oracle SQL, and trying to figure out how to always return the rows from a given table when seeing the results. So, for a simple example:

Table: Students

Student_ID

Name

Creation_Date

Table: Classes

Class_ID

Dept_ID

Class_name

Student_ID

Class_Start_Date

Class_End_Date

If I wanted to query showing all students in the Student table, and a count of how many classes they are registered to, I could do:

SELECT

Students.Name, count(Classes.class_ID)

FROM

Students

LEFT OUTER JOIN Clases

on Students.Student_ID = Classes.Student ID

GROUP BY

Students.Name

;

Here is my problem: I want to run the same query as above and also filter on class_start_date, but I still want to show all students whether they have a class within the date range filtered for or not. I tried using:

WHERE (class_start_date between '01-JAN-2019' and '01-APR-2019' OR class_start_date is null)

This seems to work, but only when the student has no classes. If the student has classes where the date falls outside that condition, the name is missing from the output (i.e.: If student does not exist in classes table, student name shows up; if student has classes in the date range, Student name shows up; if student has classes, but none in the date range, student does not show up).

For students with classes but none in the date range, I would like to return Student Name with count of 0.

How can I trick SQL into doing what I want. :)

Author
Account Strength
80%
Account Age
8 years
Verified Email
Yes
Verified Flair
No
Total Karma
216
Link Karma
110
Comment Karma
79
Profile updated: 3 days ago
Posts updated: 10 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago