I am new to postgresql. Trying to understand the reason for erroneous results from Postgres and would like to learn how to rectify it.
I have a students table. When I execute the query
Select stud_id, batch_type, subject, jdate ,subj_id, sdtime, subj_hours form studs
ORDER BY jdate DESC, subject DESC, stud_id ASC LIMIT 15 OFFSET 0
I get the following corect result as expected:
Stud_id bpchar |
Batch_type Character varying |
Subject Character varying |
Jdate date |
Subj_id integer |
Sdtime Timestamp without time zone |
Subj_hours integer |
---|---|---|---|---|---|---|
3591f1gff960h09l | Residential | Software Systems Development 7 | null | 35 | 2024-03-20 12:42:55.040189 | 10 |
983e292ce1xy69c0 | Residential | Software Systems Development 5 | null | 35 | 2024-03-20 12:42:55.040189 | 14 |
7k992ad576842507 | Residential | Software Systems Development 4 | null | 35 | 2024-03-20 12:42:55.040189 | 12 |
b9ahibji8jgaeth2 | Residential | Software Systems Development 3 | null | 35 | 2024-03-20 12:42:55.040189 | 10 |
5758uh95376eb0b4 | Residential | Software Systems Development 2 | 2024-03-20 | 35 | 2024-03-20 12:42:55.040189 | 12 |
6ch9b2f7894740er | Residential | Software Systems Development | 2024-03-20 | 35 | 2024-03-20 12:42:55.040189 | 14 |
a877450586v3869h | Residential | Software Systems Development | 2024-03-20 | 35 | 2024-03-20 12:42:55.040189 | 14 |
78635a8s1586d95c | Residential | Software Systems Development | 2024-03-15 | 35 | 2024-03-20 12:42:55.040189 | 14 |
b58c7fbf57328468 | Residential | Software Systems Development | 2024-03-15 | 35 | 2024-03-20 12:42:55.040189 | 16 |
acb8g94351e84226 | Residential | Software Systems Development | 2024-02-25 | 35 | 2024-03-20 12:42:55.040189 | 15 |
fvhud7653fd85m1s | Residential | Software Systems Development | 2024-02-20 | 35 | 2024-03-20 12:42:55.040189 | 16 |
b7hf962ffb6he96j | Residential | Design and Technology | 2024-02-19 | 35 | 2024-03-20 12:42:55.040189 | 14 |
394ij84275c6e97d | Residential | Software Systems Development | 2024-01-15 | 35 | 2024-03-20 12:42:55.040189 | 16 |
when I try filter the results by adding Where condition in the query as below:
Select stud_id, batch_type, subject, jdate ,subj_id, sdtime, subj_hours form studs
Where subject < ’ Software Systems Development 5’ AND stud_id > ‘983e292ce1xy69c0’
ORDER BY join_date DESC, subject DESC , stud_id ASC LIMIT 15 OFFSET 0
I get erroneous result as follows:
Stud_id bpchar |
Batch_type Character varying |
Subject Character varying |
Jdate date |
Subj_id integer |
Sdtime Timestamp without time zone |
Subj_hours integer |
---|---|---|---|---|---|---|
b9ahibji8jgaeth2 | Residential | Software Systems Development 3 | null | 35 | 2024-03-20 12:42:55.040189 | 10 |
a877450586v3869h | Residential | Software Systems Development | 2024-03-20 | 35 | 2024-03-20 12:42:55.040189 | 14 |
b58c7fbf57328468 | Residential | Software Systems Development | 2024-03-15 | 35 | 2024-03-20 12:42:55.040189 | 16 |
acb8g94351e84226 | Residential | Software Systems Development | 2024-02-25 | 35 | 2024-03-20 12:42:55.040189 | 15 |
fvhud7653fd85m1s | Residential | Software Systems Development | 2024-02-20 | 35 | 2024-03-20 12:42:55.040189 | 16 |
b7hf962ffb6he96j | Residential | Design and Technology | 2024-02-19 | 35 | 2024-03-20 12:42:55.040189 | 14 |
but I was expecting the following result.
Stud_id bpchar |
Batch_type Character varying |
Subject Character varying |
Jdate date |
Subj_id integer |
Sdtime Timestamp without time zone |
Subj_hours integer |
---|---|---|---|---|---|---|
7k992ad576842507 | Residential | Software Systems Development 4 | null | 35 | 2024-03-20 12:42:55.040189 | 12 |
b9ahibji8jgaeth2 | Residential | Software Systems Development 3 | null | 35 | 2024-03-20 12:42:55.040189 | 10 |
5758uh95376eb0b4 | Residential | Software Systems Development 2 | 2024-03-20 | 35 | 2024-03-20 12:42:55.040189 | 12 |
6ch9b2f7894740er | Residential | Software Systems Development | 2024-03-20 | 35 | 2024-03-20 12:42:55.040189 | 14 |
a877450586v3869h | Residential | Software Systems Development | 2024-03-20 | 35 | 2024-03-20 12:42:55.040189 | 14 |
78635a8s1586d95c | Residential | Software Systems Development | 2024-03-15 | 35 | 2024-03-20 12:42:55.040189 | 14 |
b58c7fbf57328468 | Residential | Software Systems Development | 2024-03-15 | 35 | 2024-03-20 12:42:55.040189 | 16 |
acb8g94351e84226 | Residential | Software Systems Development | 2024-02-25 | 35 | 2024-03-20 12:42:55.040189 | 15 |
fvhud7653fd85m1s | Residential | Software Systems Development | 2024-02-20 | 35 | 2024-03-20 12:42:55.040189 | 16 |
b7hf962ffb6he96j | Residential | Design and Technology | 2024-02-19 | 35 | 2024-03-20 12:42:55.040189 | 14 |
394ij84275c6e97d | Residential | Software Systems Development | 2024-01-15 | 35 | 2024-03-20 12:42:55.040189 | 16 |
Can someone help me understanding the reason for the erroneous result and how to rectify this issue please. Thanks in advance.
qquest is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.