jemz — 2012-12-15T10:28:51-05:00 — #1
Hi, I just want to ask because i am confuse with my three tables,..my question is..Is it possible to use the join query like the inner join,left join,outer join.,etc...in the 3 tables, as i know that when we use the inner join it must be the pk and fk,example:..
select e.emp_no, e.f_name,e.l_name,p.proj_no,p.res_empno
from employee e join project p
on e.emp_no = p.res_empno
the emp_no is pk for the employee table and the res_empno is the fk for the project table.
but what if the design of my table is something like this
std_idno = pk
rm_stdno = pk
I want that if the student has the same classno in the table2 i want to display the rm_size and the rm_description,student name and idno.
Is it possible to use the join query on this,can i populate the exact data?please help me on this I am really confuse....
I am using wamp and i create the database in the phpmyadmin.
Thank you in advance
cpradio — 2012-12-15T10:53:30-05:00 — #2
First off, here is a brief definition of each join
Second, based on what you are asking, you want to show students and their associated class so long as that class exists in table2.
So I believe you could theoretically use any of the joins for this scenario, but it seem inner join may be best suited.
SELECT rm_size, rm_description, std_fname, std_lname, std_idno FROM table1 AS Student INNER JOIN table2 AS Room ON Student.std_classno = Room.rm_stdclassno
jemz — 2012-12-15T11:01:14-05:00 — #3
Hi cpradio, Thank you so much for the reply,,....I forgot to put that the Student.std_classno and Room.rm_stdclassno have different data types and length associated...
cpradio — 2012-12-15T11:02:39-05:00 — #4
Okay, but do the values match up or what would you need to do to make the columns match up?
Can you give sample data stored in both tables and then the desired returned result you want to see?
jemz — 2012-12-15T11:11:35-05:00 — #5
Hi cpradio,..I apologize for my last reply,I mean to say that Student.std_classno and Room.rm_stdclassno is not a foreign key and also it is not a primary key...but they both having the same values and datatypes...my question is this,is it okay to use inner join even they are not pK and Fk?can i still get the right data?.
cpradio — 2012-12-15T11:13:10-05:00 — #6
Yes, you can still get the right data. It would be nice if they had some sort of relationship to verify data integrity, but that is the only issue the fk relationship would resolve. It would prevent both tables from having invalid data.
jemz — 2012-12-15T11:25:31-05:00 — #7
Hi thank you for this, but for example the table is already created how can i know that this table have FK relationship to other tables ?by the way i do this in phpmyadmin.
cpradio — 2012-12-15T12:10:28-05:00 — #8
I don't use phpmyadmin a lot, but maybe this video will be helpful
jemz — 2012-12-15T12:13:58-05:00 — #9
Hi, cprdio thank you for helping me, Okay i will watch this video.and i will write back to you again if i get in trouble.
More power to you always.