On Oct 10, 3:22 pm, Christer Nilsson <[email protected]>
wrote:
> Example:
>
> Database A:
>
>   Humans
>     ID
>     Name
>
> Database B:
>
>   Pets
>     ID
>     Owner_ID
>     Name
> I would like to know the names of all humans with pets named Ajax.
>
> SELECT A.Humans.Name
> FROM A.Humans
> JOIN B.Pets ON B.Pets.Owner_ID = A.Humans.ID
> WHERE B.Pets.Name = 'Ajax'
>
> Is it possible to express this in Sequel?
>
> Thanks for all earlier rapid answers!

Depends on the database support.  Some databases support linking other
databases and referencing them like that:

DB[:a__humans___h].
  join(:b__pets___p, :owner_id=>:id).
  select(:h__name).
  filter(:p__name=>'Ajax')

However, you should be able to do what you want using 2 queries in a
database independent manner:

  DBA[:humans].
    select(:name).
    filter(:id=>DBB[:pets].
      select(:owner_id).
      filter(:name=>'Ajax').
      map(:owner_id))

Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to