Results 1 to 6 of 6
Related
-
Select Query Forum: Databases
Replies: 2 -
How to select multiple values from a table? Forum: Databases
Replies: 1 -
SELECT Choose 1 but send 2 values? Forum: HTML Forum
Replies: 0 -
Will Paypal you $20 to write this one line select query Forum: PHP Forum
Replies: 2
-
03-16-2007, 05:16 AM #1
retreiving values from sql using a complicated select query.
am having a problem with sql.
i have a table A. in that i have three columns a,student1,student2. it is the primary key of table A and student id of two different students. i have another table student which includes the student id and student name. now i have to display the following:
Table A's primary key, corresponding student1's name and corresponding students2's name.
if we use select * from A we get only the student ids. i need them to be replaced by their names.
can any one help me. please...
Last edited by hermoine; 03-16-2007 at 05:28 AM. Reason: to mention Q for sql query
-
03-16-2007, 07:19 AM #2
Re: retreiving values from sql using a complicated select query.
Sorry, I'm a bit confused about your table structure. Could you list table names and data elements, something along these lines:
Code:Table 1 Field 1 Field 2 Table 2 Field 1 Field 2
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
-
03-20-2007, 01:42 AM #3
Re: retreiving values from sql using a complicated select query.
Code:Table 1 - Student student id - primary key student name Table 2 id - primary key student 1 student 2
I want to display the table 2 in my form. But the form should contain only the names of the students but not their ids. how can i link them. since there are columns pointing to the same primary key simple joins are not working.
-
03-20-2007, 06:08 AM #4
Re: retreiving values from sql using a complicated select query.
Let me see if I understand this correctly. Student 1 is an id which links to Student id in the Student table. Student 2 is also an id which links to Student id in the Student table. Do I have that right? If so, here's how to get all the student names:
Code:(select * from Student inner join Student on student id = student 1) union (select * from Student inner join Student on student id = student 2)
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
-
03-20-2007, 07:08 AM #5
Re: retreiving values from sql using a complicated select query.
thanks a lot vinyl-junkie,
its some what what i need. but i got the idea of inner join.
Code:select a.a, st1.studentname, st2.studentname from a inner join students st1 on a.student1 = st1.studentid inner join students st2 on a.student2 = st2.studentid
once again thanks for taking pains to give me a solution.
-
03-20-2007, 07:19 AM #6
Re: retreiving values from sql using a complicated select query.
I'm glad I could help.
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum