karthika44 Posted March 6, 2020 Share Posted March 6, 2020 i have two tables, employee details table(empno, emp_name , branch) and attendance table(date, Ot, attendence). I want to create a relation between two tables Quote Link to comment https://forums.phpfreaks.com/topic/310214-create-a-relation-between-two-tables-mysql/ Share on other sites More sharing options...
Phi11W Posted March 6, 2020 Share Posted March 6, 2020 Since the two tables have no fields in common, I assume you want a linking table ("Weak Entity") between the two, something like this: create table employee_attendance ( empno ... , att_date ... , Ot ... , primary key ( empno, att_date, Ot ) , foreign key empno references employee ( empno ) , foreign key ( att_date, Ot ) references attendance( att_date, Ot ) ); I'm guessing at the primary Key for the attendance table here - an employee would attend something ("Ot?") on a given date. Don't use reserved words, like date, for table or column names. Eventually, it will come back to bite you. Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/310214-create-a-relation-between-two-tables-mysql/#findComment-1575188 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.