# Using SQL to reference multiple tables in VB6



## B3gbie (Nov 30, 2001)

I am attempting to set up a database frontend within vb, and would like to select a record something like this:

SELECT * FROM TableA WHERE Requirement = something in a particular field IN TableB

Any help with this sort of SQL (including links to websites with examples) would be greatly appreciated.


----------



## TimCottee (Oct 10, 2001)

As far as VB is concerned it doesn't have any concern over the way you phrase your query. As long as your query is valid in terms of the syntax of your database then it will work as written.

You have the right kind of idea, it just depends on exactly what sort of resultset you expect to get:

SELECT * FROM TableA Inner Join TableB On TableA.Key = TableB.Key

Will return all records from table A where a key field is equal to a key field in a record in table B.

SELECT * FROM TableA Where TableA.Field IN (SELECT KeyField From TableB)

Returns all records from TableA where the value of TableA.Field exists in the column KeyField in TableB.

Whilst these two may appear similar they can return different results depending on the data that is in both tables.


----------

