Solved

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

Posted on 2000-02-27
8
187 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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