SELECT DISTINCT table3.ID, table3.Company
FROM         table3 INNER JOIN
                      table2 ON table3.ID = table2.t2_ID INNER JOIN
                      table1 ON table2.ordernumber = table1.ordernumber
WHERE     (table1.productcode LIKE '%a certain string%')

On Thu, May 26, 2011 at 11:41 AM, Mark Atkinson <ma...@aocs.org> wrote:

>
> Hallo all,
>
> Forgive my SQL "injection" into this list - perhaps an answer to my
> question might also prove useful to others.
>
> I'm using three tables. There is no relationship between table1 and table3.
>
> I first query table1 for ordernumber and productcode, based on the
> productcode containing a certain string.
>
> Outputting the results, I query table2 for ordernumber and t2_ID based on
> table2.ordernumber matching table1.ordernumber.
>
> Looping those results, I query table3 for ID and Company based on
> table2.t2_ID.
>
> This, rather painfully I do admit, finds the table3.Company(ies) that
> has(have) purchased table1.productcode.
>
> Have Googled and read about how a single select with JOIN and/or UNION
> would achieve these results, but they also mention how I should essentially
> "start at the end" and work my way backwards, so to speak. Can't quite get
> my head around this.
>
> TIA for any advice.
> Mark
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:344917
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to