Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select from table with composite primary key

I have an injection table called StudentSchool that contains :

StudentSchoolID  StudentId   SchoolID
1                233         22

But now I want to make the table with composite primary key like this:

StudentId   SchoolID
    233         22

In the first case I select using

select * from StudentSchool  
where (StudentId = 233) and (SchoolID = 22)      

but in the second case how to do that with it as it is a primary key

like image 983
Eslam Soliman Avatar asked Aug 22 '11 11:08

Eslam Soliman


2 Answers

I'm not sure if I understand the question correctly.
If you want the student with StudentId 233 and SchoolId 22, then it's the same query like for the first case.

like image 102
Christian Specht Avatar answered Nov 02 '22 08:11

Christian Specht


Maybe I am missing something but your query would be the same

select * from YourNewTable  where (StudentId  =233)and (ScoohlID=22) 
like image 36
Taryn Avatar answered Nov 02 '22 06:11

Taryn