How to get the record?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Tassadduq
Forum Commoner
Posts: 60
Joined: Wed Dec 03, 2008 2:53 pm

How to get the record?

Post by Tassadduq »

Hi everyone, i have two tables one for students records and one for daily attendance record. Every student has his own student code to use for daily attendance. In morning ever one comes and mark his attendance using his code. Attendance table stores the current date and student id. Now the issue is very simple. i want to get the students list those were absent today means not in attendance table.

Here are the tables structure.

Students
.sid
.name
.scode

Attendance
.id
.stdid
.date


i want to get the students list that are not in attendance table on given date.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to get the record?

Post by requinix »

SELECT from the attendance table then RIGHT JOIN the students and filter WHERE the student is NULL (ie, no row joined) and the attendance date is today.
User avatar
Tassadduq
Forum Commoner
Posts: 60
Joined: Wed Dec 03, 2008 2:53 pm

Re: How to get the record?

Post by Tassadduq »

Can you please write the query? how to??

i made it like this

Code: Select all

SELECT attendance.*, students.name FROM attendance RIGHT JOIN students ON (attendance.std_id = students.id) WHERE att_date = '2013-04-04' AND std_id = NULL;
but it did not work... :(
Any help please....
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to get the record?

Post by requinix »

I've thoroughly confused myself now... I could swear you've edited your post... but I am confident I misspoke: the attendance date needs to be in the JOIN condition.

Code: Select all

SELECT attendance.*, students.name FROM attendance RIGHT JOIN students ON (attendance.std_id = students.id AND attendance.att_date = '2013-04-04') WHERE attendance.std_id IS NULL
User avatar
Tassadduq
Forum Commoner
Posts: 60
Joined: Wed Dec 03, 2008 2:53 pm

Re: How to get the record?

Post by Tassadduq »

Thanks alot. it works superbbbbb..... :)
Post Reply