Parent/Child dataset select

  • Thread starter Thread starter Midtown2oo3
  • Start date Start date
M

Midtown2oo3

Parent table
--------------------
Key
Count
Name
Type

Child table
--------------------
Key
ParentKey
Account
Department

"ParentKey" is a foreign key between the two tables.

I would like to perform a select as such: ChildTable.Select
([Department] = 'Dept1' AND Parent.[Type] = 'Public')

Is this even a possibility?

Thanks in advance.
 
First of all, what do you want the result to be? Second, it sounds like you
should be looking at a newsgroup for SQL, possibly one of the
microsoft.public.sqlserver newsgroups.
 
Child table
--------------------
Key
ParentKey
Account
Department

"ParentKey" is a foreign key between the two tables.

I would like to perform a select as such: ChildTable.Select
([Department] = 'Dept1' AND Parent.[Type] = 'Public')

Is this even a possibility?


From a SQL standpoint? Very easy:

SELECT Child.*
FROM Child c
JOIN Parent p
ON c.ParentKey = p.Key
WHERE c.Department = @Dept
AND p.Type = @Type

From a DataSet, Entity or LINQ to SQL. Also easy enough, once you have
the model with both items. It still follows the basic idea shown in the
SQL query above.

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top