Solved

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

Posted on 2000-02-27
8
186 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 106
bigDiff challenge 17 83
wordmultiple challenge 12 117
"Black Box" Testing of Control System Software 2 21
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now