简体   繁体   中英

How to join tables and queries in C# with access database

this is how i join 2 tables and select form it:

OleDbDataAdapter DataA = new OleDbDataAdapter(@"Select tfr.FeedID, tf.FeedName, tfr.FeedQuantity, tf.DM
                                                        FROM tFeeds AS tf
                                                        INNER JOIN tFeedsRations AS tfr ON (tf.FeedID=tfr.FeedID)", Connection);

but what about adding a access query to this select command? for example I want to add this statement to my select command:

Select qfq.FeedDMQuantites
From qFeeds_Quantities as qfq

what should I do?

Well add another JOIN condition to this table qFeeds_Quantities (assuming you have a relationship to this table or a common column among other table).

Assuming you have a common column like FeedID in this new table as well you can make another JOIN like

select tfr.FeedID, tf.FeedName, tfr.FeedQuantity, 
tf.DM, qfq.FeedDMQuantites
FROM (tFeeds AS tf
INNER JOIN tFeedsRations AS tfr ON tf.FeedID = tfr.FeedID)
INNER JOIN qFeeds_Quantities as qfq ON tf.FeedID = qfq.FeedID;

If you want to include another JOIN then parenthesize like

FROM ((tFeeds AS tf
INNER JOIN tFeedsRations AS tfr ON tf.FeedID = tfr.FeedID)
INNER JOIN qFeeds_Quantities as qfq ON tf.FeedID = qfq.FeedID)
INNER JOIN BLAH AS bll ON bll.test = tf.test;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM