john666 Posted November 14, 2013 Share Posted November 14, 2013 Hi Guys.. Im new in PHP and Mysql 1 have Two table 1.students 2nd classes i want to Set Primary key and Foreign Key in student Table and want to use Join Query on both Help me in that student Fields 1..(sn)seriel number 2..std_name 3.std_father_name 3..std_roll_num 4..std_class 5..std_cell 6..std_address 7..std_dob 8..std_address 9..std_fee table 2 classes fields 1.class_id 2.class_name 3.date_created what will be Primary key and foreign key here and join query to retrieve record using phpmyadmin need step by step guide thanks Link to comment https://forums.phpfreaks.com/topic/283885-primary-and-foreign-key-help/ Share on other sites More sharing options...
Barand Posted November 14, 2013 Share Posted November 14, 2013 +--------------+ +-------------------+ | class | | student | +--------------+ +-------------------+ | class_id (PK)|--+ | serial number (PK)| | class_name | | | std_name | | date_created | | | std_father_name | +--------------+ | | std_roll_num | +---<| std_class (FK)| | std_cell | | std_address | | std_dob | | std_fee | +-------------------+ The primary keys are the unique identifiers of each record. Assuming std_class contains the id of the student's class then that would be a foreign key. To query the table using a JOIN you would have a query like this SELECT c.class_name, s.std_name, s.std_father_name FROM student as s INNER JOIN class as c ON s.std_class = c.class_id ORDER BY c.class_name Note that you need InnoDB tables to define foreign key constraints. You do not have to formally define a foreign key to use a field in a join. Link to comment https://forums.phpfreaks.com/topic/283885-primary-and-foreign-key-help/#findComment-1458274 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.