Re: Finding Records
From: Geoff Jones (nodamnspam_at_email.com)
Date: 01/26/05
- Next message: Charles Evans: "Re: msado15 crashes"
- Previous message: DS: "Re: ADO Recordcount = -1"
- In reply to: Stephen Howe: "Re: Finding Records"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 26 Jan 2005 11:32:18 -0000
Thanks guys!
"Stephen Howe" <stephenPOINThoweATtns-globalPOINTcom> wrote in message
news:%23Bba4dvAFHA.1296@TK2MSFTNGP10.phx.gbl...
>> Can anybody give me some advice on the following?
>>
>> Suppose I have two tables: A and B. There is a one to many relationship
>> between A and B. I would like to find all the child rows in B for a given
>> row in A. Then, from these returned rows, I would like to find all the
> rows
>> which satisfy a given criteria.
>>
>> With me so far? :)
>
> Yes. Use SQL. You don't want to ever do in code what can be done in SQL.
> The SQL engine for most databases is more powerful than what hand-coding
> with loops could achieve. So use it :-)
>
> If you find yourself iterating through Recordsets, comparing doing finds
> etc, this will normally always be a poorer solution than 1 SQL command
> that
> achieves the same results. Same for INSERTs, DELETEs, UPDATEs even if
> complex. So you want to learn how to express yourself in SQL. It is very
> powerful.
>
> For this problem you want an (INNER) JOIN and a WHERE clause
>
> You don't say what you want to do with the rows you get back. I assume you
> want to see them, so SELECT
>
> SELECT A.field1, A.field2, A.fieldN, B.field1, B.field2
> FROM A JOIN B ON A.fieldincommon1=B.fieldincommon2
> [WHERE yourcriteria]
> [ORDER BY 1,2,3]
>
> should do it.
>
> (i) In the SELECT clause put whatever fields you want to see returned
> (ii) In the optional WHERE clause specify your criteria for restriction.
> Without a WHERE clause all matching rows are returned
> (iii) In the optional ORDER clause 1,2,3 means order by the columns
> specified in the SELECT clause. You can do
>
> ORDER BY A.field1, A.field2, A.fieldN
>
> instead. If you don't care about ORDER, records may come back in any old
> order.
>
> In ADO, if this was a Recordset Open() or Command Execute, you will get
> back
> a recordset consisting of the fields you select and only records that
> match
> the WHERE clause.
> For each entry in A you will get back as many B entries that match and A
> fields will be duplicated for that A entry but the B fields in the SELECT
> will be what matches the A entry.
>
> Stephen Howe
>
>
- Next message: Charles Evans: "Re: msado15 crashes"
- Previous message: DS: "Re: ADO Recordcount = -1"
- In reply to: Stephen Howe: "Re: Finding Records"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|