473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

retrieving information from 2 tables

Hi everyone,

Could someone please help me out. I am having problems retrieving information from a table where 2 attributes are foreign keys of the SAME attribute in another table....

The tables are
USER(id, name, type_login)
STUDENT(student_id, mentor_id)

here, student_id and mentor_id are foreign keys of the USER table....
I need to get a list of all the students with their respective mentors....
I think the problem is because we are referencing the same coloumn of the user table....

Looking forward to a reply soon!
Thanks & Regards
Gunjan
Sep 21 '08 #1
1 1566
Hi,

You can write the qry in inline view to find out the details,

Here is the sample,

SELECT
S.student_id,
S.mentor_id,
(SELECT name FROM USER WHERE id=S.student_id) as STUDENT_NAME,
(SELECT type_login FROM USER WHERE id=S.student_id) as STUDENT_TYPE_LOGIN,
(SELECT name FROM USER WHERE id=S.mentor_id) as MENTOR_NAME,
(SELECT type_login FROM USER WHERE id=S.mentor_id) as MENTOR_TYPE_LOGIN
FROM
STUDENT S


Thanks
Bhuvanesh
Sep 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Programatix | last post by:
Hi, I'm working on a project which includes WebServices and Windows Form application. The Windows Form application will call the WebServices to retrieve data from database. The data will be...
1
by: Mike Fellows | last post by:
im trying (with great difficulty) to retrieve 1 item of data from a dataset im trying to put the piece of data into a string from column 0 row 1 here is my code (i guess you will see what im...
6
by: Dean Slindee | last post by:
Does anybody have an actual example of retrieving an Image data type column from a SQL Server table using a dataset (not a datareader)? I would like to see the statements that would move the...
2
by: RSH | last post by:
I am struggling a bit trying to get at all of the Table names in a given Access database. I have the code below which should be retrieving the information...i am just having a bit of trouble...
5
by: aniket_sp | last post by:
i am using a data adapter and a dataset for filling and retrieving data into .mdb database. following is the code..... for the form load event Dim dc(0) As DataColumn Try If...
2
by: Sakke | last post by:
Hello! We have written a GCryptoSvr.dll COM server in C++. Inside that resides WebClient COM component. WebClient CLSID is {8DC27D48-F94C-434B-A509-C3E1A3E75B9E}. When we are using that...
1
by: jimmyfo | last post by:
Hi, I recently wrote an ASP.Net web application in VS2005 and published (using VS2005 Publish feature) it to a relatively clean machine with ASP.Net 2.0 and MDAC 2.8 installed on it. However, when...
1
by: Chris | last post by:
Hi, I'm using the following code DataTable tables = ((OleDbConnection)oleconn).GetOleDbSchemaTable( OleDbSchemaGuid.Tables, new object { null, null, null, "TABLE" }); foreach (DataRow r in...
4
AaronL
by: AaronL | last post by:
Hello again, First I want to say thank you to all of you that have helped me in the past with all of my questions. I have gotten far in PHP and MySQL in the past two weeks. I designed a site...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.