Wednesday, March 7, 2012

Obtaining data from different tables in the same database

Hi

I've been doing a website with ajax controls and I have tables that has foreign key relationships and hence the main page requires the data from the tables from the foreign keys stored in a separate table. Can anyone help me out with the proper way of querying the tables. Am not able to work out the way with the joins that SQL express provides.

Thanks

Here's a sample query:

TableA contains 3 columns: Data1, Data2, ForeignKey
TableB contains 2 columns: RecordId, SomeOtherData

The RecordId value from TableB has been stored in the ForeignKey column of TableA

SELECT TableA.Data1, TableA.Data2, TableB.SomeOtherDataFROM TableAINNERJOIN TableBON TableA.ForeignKey = TableB.RecordId

Each row of data that is retrieved will look like:

Data1,Data2, [ForeignKey] <--> [RecordId],SomeOtherData

No comments:

Post a Comment