mysql - Need a SQL command for these tables -
i have following 2 tables (student , attendance):
mysql> describe student; +----------------------+--------------+------+-----+---------+----------------+ | field | type | null | key | default | | +----------------------+--------------+------+-----+---------+----------------+ | student_id | int(11) | no | pri | null | auto_increment | | student_email | varchar(255) | yes | | null | | | student_phone_number | varchar(255) | yes | | null | | | parent_first_name | varchar(255) | no | | null | | | parent_last_name | varchar(255) | no | | null | | | parent_email | varchar(255) | no | | null | | | parent_phone_number | varchar(255) | no | | null | | | first_name | varchar(255) | no | | null | | | last_name | varchar(255) | no | | null | | | days_absent | int(11) | yes | | null | | | days_tardy | int(11) | yes | | null | | | class_id | int(11) | no | mul | null | | +----------------------+--------------+------+-----+---------+----------------+ mysql> describe attendance; +-----------------+------------+------+-----+---------+-------+ | field | type | null | key | default | | +-----------------+------------+------+-----+---------+-------+ | student_id | int(11) | no | pri | null | | | class_id | int(11) | no | pri | null | | | attendance_date | date | no | pri | null | | | absent | tinyint(1) | yes | | null | | | tardy | tinyint(1) | yes | | null | | | note | text | yes | | null | | +-----------------+------------+------+-----+---------+-------+
i want check attendance , email of children absent or tardy day. there sql statement can use can, example, select students attendance absent/tardy value = 1, using student_id specified in attendance table, pull student info student table attendance.student_id = student.student_id?
just try exists
select student_email,student_phone_number student std exists( select 1 attendance atd std.student_id = atd.student_id , (atd.absent =1 or atd.tardy =1) )
just make sure select info student table , exists filter in attendance talbe. condition student_id.
also if need info attendance talbe, use join.
Comments
Post a Comment