SQL stmt on 2 databases

SQL stmt on 2 databases

am 27.03.2006 00:57:35 von jess

Hi,
I'm not sure what the right SQL statement would be.
In 1 database there's a table of parent companies and a table of child
companies. The parents have a key in their table. The childs have their own
key plus the parent key in another column.
In the 2 database there's a list of events that were done for either a
parent group (parent key)or a child(child key)(same column).
What would the SQL statement be to call up all events for a parent - when
some of the events are registered under the children?
So I go to the child table and pull a list of child keys that have a
specific parent key. But how do I then write an SQL statement refering to
all the results of the child table query?

Re: SQL stmt on 2 databases

am 27.03.2006 02:09:03 von reb01501

Jess wrote:
> Hi,
> I'm not sure what the right SQL statement would be.
> In 1 database there's a table of parent companies and a table of child
> companies. The parents have a key in their table. The childs have
> their own key plus the parent key in another column.
> In the 2 database there's a list of events that were done for either a
> parent group (parent key)or a child(child key)(same column).
> What would the SQL statement be to call up all events for a parent -
> when some of the events are registered under the children?
> So I go to the child table and pull a list of child keys that have a
> specific parent key. But how do I then write an SQL statement
> refering to all the results of the child table query?

We sill be unable to help unless you provide the type and version of
database you are using (this is almost always relevant - never ask a
db-related question without providing it), as well as a description of the
table names, the relevant field names and datatypes, and the names of the 2
databases involved.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Re: SQL stmt on 2 databases

am 27.03.2006 02:27:25 von Hal Rosser

"Jess" wrote in message
news:B8306796-074D-47E6-AD47-2A6E2E2C57DE@microsoft.com...
> Hi,
> I'm not sure what the right SQL statement would be.
> In 1 database there's a table of parent companies and a table of child
> companies. The parents have a key in their table. The childs have their
own
> key plus the parent key in another column.
> In the 2 database there's a list of events that were done for either a
> parent group (parent key)or a child(child key)(same column).
> What would the SQL statement be to call up all events for a parent - when
> some of the events are registered under the children?
> So I go to the child table and pull a list of child keys that have a
> specific parent key. But how do I then write an SQL statement refering to
> all the results of the child table query?

Are you talking about 2 seperate Databases - or just 2 different Tables of
the same database ?
If 2 different databases, you'll need 2 connections, and you retrieve one
set of records from one database - then loop thru those records and access
the second database. One SQL statement won't do it.
If you're working with one database and 2 tables, then look at inner joins.

Re: SQL stmt on 2 databases

am 30.03.2006 14:21:04 von mmcginty

"Hal Rosser" wrote in message
news:KgGVf.19291$qe.3347@bignews1.bellsouth.net...
>
> "Jess" wrote in message
> news:B8306796-074D-47E6-AD47-2A6E2E2C57DE@microsoft.com...
>> Hi,
>> I'm not sure what the right SQL statement would be.
>> In 1 database there's a table of parent companies and a table of child
>> companies. The parents have a key in their table. The childs have their
> own
>> key plus the parent key in another column.
>> In the 2 database there's a list of events that were done for either a
>> parent group (parent key)or a child(child key)(same column).
>> What would the SQL statement be to call up all events for a parent - when
>> some of the events are registered under the children?
>> So I go to the child table and pull a list of child keys that have a
>> specific parent key. But how do I then write an SQL statement refering
>> to
>> all the results of the child table query?
>
> Are you talking about 2 seperate Databases - or just 2 different Tables of
> the same database ?
> If 2 different databases, you'll need 2 connections, and you retrieve one
> set of records from one database - then loop thru those records and access
> the second database. One SQL statement won't do it.
> If you're working with one database and 2 tables, then look at inner
> joins.

If the OP is using SQL Server as the db back-end, he can reference tables in
any number of databases, in the same SQL statement, using 3-part names (and
could even reference tables across multiple servers running different db
engines, using linked servers and 4-part names.)

Thus the reason Bob always asks, rather than assumes, exactly which db
technology the OP is using: a meaningful answer is often impossible without
that info. (This would be one of those times.)

-Mark