October 17th, 2013, 07:48 AM
Sorry, i am just a beginner and looking to tune up my query.
Select student_id,net_id from nstudent where status_id=3 inner join ndepart using (net_id) where not deleted;
The above query shows the result but i also want to get the depart_name which is ndepart table, but i cannot figure out how would i do it (probably in descending order)?
student_id,net_id are bigint. depart_name is character, and status_id is integer. Also net_id is primary key for ndepart and foreign key in nstudent and student_id is primary key for nstudent.
October 17th, 2013, 08:02 AM
You can always reference any column in any of the joined tables by prefixing the tablename using a dot:
SELECT foo.x, foo.this, bar.that
INNER JOIN bar ON foo.x = bar.y;
If the fieldname is unique then you don't have to refix, but it is good practice to always do it anyway. Otherwise, crappy databases like MySQL will not warn you that, for example, both tables have a column named "id", and you will never know which you got in your result.