Solved

multible tables in a crecord class...how to join

Posted on 2000-02-27
8
189 Views
Last Modified: 2013-11-20
how do you join tables and make a single CRecordSet class for amany tables
?

0
Comment
Question by:ghimireniraj
8 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 2564079
Hi neeraj.

How R U?....

I dont know much about the database, but I am giving this comment with the help of one of my friend. Have U tried like this?....

CRecordset rs;
rs.Open(CRecordset::dynaset, "SELECT * FROM tab1, tab2");

Try it out.
VinExpert
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2564345
INNER JOIN combines records from two tables whenever there are matching values in a common field.

Syntax:
FROM table1 INNER JOIN table2 ON table1.field1 compopr table2.field2

table1 & table2      are the names of the tables from which records are combined.

field1 & field2      are the names of the fields that are joined. If they aren't numeric, the fields must be of the same data type and contain the same kind of data, but they don't have to have the same name.

compopr is any relational comparison operator: "=," "<," ">," "<=," ">=," or "<>."

The following example shows how you could join the Categories and Products tables on the CategoryID field:

CRecordset rs;
rs.Open(CRecordset::dynaset, "SELECT CategoryName, ProductName
FROM Categories INNER JOIN Products
ON Categories.CategoryID = Products.CategoryID");

In the preceding example, CategoryID is the joined field, but it isn't included in the query output because it isn't included in the SELECT statement. To include the joined field, include the field name in the SELECT statement - in this case, Categories.CategoryID.
0
 
LVL 3

Accepted Solution

by:
V_Bapat earned 20 total points
ID: 2564351
You can also link several ON clauses in a JOIN statement, using the following syntax:

SELECT fields FROM table1 INNER JOIN table2 ON table1.field1 compopr table2.field1 AND ON table1.field2 compopr table2.field2 OR
ON table1.field3 compopr table2.field3;

You can also nest JOIN statements using the following syntax:

SELECT fields FROM table1 INNER JOIN
(table2 INNER JOIN [( ]table3 [INNER JOIN [( ]tablex [INNER JOIN ...)] ON table3.field3 compopr tablex.fieldx)]  ON table2.field2 compopr table3.field3)
ON table1.field1 compopr table2.field2;

NOTE : A LEFT JOIN or a RIGHT JOIN may be nested inside an INNER JOIN, but an INNER JOIN may not be nested inside a LEFT JOIN or a RIGHT JOIN.

Vicky
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:ghimireniraj
ID: 2565869
Thanks for your comments.But my ojjective was to form a record set object  out of the join ?
How do i do that?
0
 
LVL 3

Author Comment

by:ghimireniraj
ID: 2565897
BAPAT  answer , i think will sole it .I am sorry i forget to read one part of it
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2567712
>>Thanks for your comments.But my ojjective was to form a record set object  out of the join ?
>>How do i do that?

I think my post answers it. Feel free to ask if you have any query.

Vicky
0
 

Expert Comment

by:SDU
ID: 2581457
Create a view on your database (that can take parameters if you want)
(I think the SQL statement is CREATE VIEW...)
Then after, base your recordset on that view like if it was an ordinary table.

That's it
Hope it helps.
0
 
LVL 3

Author Comment

by:ghimireniraj
ID: 2631561
thx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 102
Process filename extension 3 208
tripleUp challenge 7 92
Fibonacci challenge 11 136
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question