Solved

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

Posted on 2000-02-27
8
185 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

17 Experts available now in Live!

Get 1:1 Help Now