?
Solved

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

Posted on 2000-02-27
8
Medium Priority
?
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 80 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
Independent Software Vendors: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 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