I have two tables in an access database. How can I create the select command for both I know that for just one table i can do this: "SELECT * FROM Table1", but from two would this work: "SELECT Table1.*, Table2.* FROM Table1, Table2"
I'll create as many datatables as the number of tables I have in my db, and attach those to my dataset. Each table contains an ID (AutoNumber) which is equal for the same record. For example:
Table Identification: ID Name Address 1 John St. Habahaba 2 Mary Av. Had a little lamb
Table Products: ID Product 1 DVD-Mulholland Drv. 2 VHS-Pulp Fiction
By this, I can say that John who lives in St. Habahaba bought DVD-Mulholland Drv; and Mary who lives in Av. Had a little lamb bought VHS-Pulp Fiction... I'm also thinking of using the field ID as a primary key...
Do you want the tables to be linked E.g., does the data in Table1 have a corresponding entry in Table2
Do you want to return the tables as more than one recordset. E.g., do you want to return Table1 then Table2
The query "SELECT Table1.*, Table2.* FROM Table1, Table2" is a valid query, however the result set returned contains is the product of the number of rows in each table. E.g. if there are 2 rows in Table1 and 2 rows in Table2 the result set returned will contain 4 rows. This might not be what you want.
sql statements...
Mark Ingram
I'll create as many datatables as the number of tables I have in my db, and attach those to my dataset. Each table contains an ID (AutoNumber) which is equal for the same record. For example:
Table Identification:
ID Name Address
1 John St. Habahaba
2 Mary Av. Had a little lamb
Table Products:
ID Product
1 DVD-Mulholland Drv.
2 VHS-Pulp Fiction
By this, I can say that John who lives in St. Habahaba bought DVD-Mulholland Drv; and Mary who lives in Av. Had a little lamb bought VHS-Pulp Fiction...
I'm also thinking of using the field ID as a primary key...
Any suggestions
Thanks
moinj
Global
Do you want to return the tables as more than one recordset. E.g., do you want to return Table1 then Table2
The query "SELECT Table1.*, Table2.* FROM Table1, Table2" is a valid query, however the result set returned contains is the product of the number of rows in each table. E.g. if there are 2 rows in Table1 and 2 rows in Table2 the result set returned will contain 4 rows. This might not be what you want.
RvA
SELECT * FROM Table1 SELECT * FROM Table2
And you will get two resultsets.
But, based on your data, you could do a JOIN:
SELECT A.Name, A.Address, B.Product FROM Table1 A
JOIN Table2 B
ON A.ID = B.ID
and your result set would look like this:
John St. Habahaba DVD-Mulholland Drv
Mary Av. Had a little lamb VHS-PulpFiction
The problem, though, is that your product data ID would be linked to your individual data ID. Which, you probably don't want...
For this situation, you probably want a 3 table approach:
Table 1:
Customer_ID Name Address
and Customer_ID is the PK
Table 2:
Product_ID Product
and Product_ID is the PK
Table 3:
Customer_ID Product_ID
Where Customer_ID and Product_ID are FKs
Then, you can create a View to synthesize the data.
Make sense