> dataset.select(:users.*).join(:subscriptions, :user_id => :id).where(:feed_id 
> => 3).distinct
=> #<Sequel::MySQL::Dataset: "SELECT DISTINCT `users`.* FROM `users`
INNER JOIN `subscriptions` ON (`subscriptions`.`user_id` =
`users`.`id`) WHERE (`feed_id` = 3)">

or

> dataset.select('DISTINCT users.*'.lit).join(:subscriptions, :user_id => 
> :id).where(:feed_id => 3)
=> #<Sequel::MySQL::Dataset: "SELECT DISTINCT users.* FROM `users`
INNER JOIN `subscriptions` ON (`subscriptions`.`user_id` =
`users`.`id`) WHERE (`feed_id` = 3)">

  Aman

On Tue, May 19, 2009 at 10:31 PM, Julien <[email protected]> wrote:
>
> Hey,
>
> I am using Sequel to build a MySQL query with a join.
>
> The query looks like that :
> SELECT DISTINCT * FROM `users` INNER JOIN `subscriptions` ON
> (`subscriptions`.`user_id` = `users`.`id`) WHERE
> (`subscriptions`.`feed_id` = 34037)
>
> Right now this returns the fields from users, but also from
> subscriptions... and I don't want them; I just the ones from users:
>
> SELECT DISTINCT users.* FROM `users` INNER JOIN `subscriptions` ON
> (`subscriptions`.`user_id` = `users`.`id`) WHERE
> (`subscriptions`.`feed_id` = 34211)"
>
>
> The example show from DataSet::Select are very light :
>
> dataset.select(:a) # SELECT a FROM items
>  dataset.select(:a, :b) # SELECT a, b FROM items
>  dataset.select{|o| o.a, o.sum(:b)} # SELECT a, sum(b) FROM items
>
> Is there a way to select fields from a specific table only?
>
> That would be great!
> >
>

--~--~---------~--~----~------------~-------~--~----~
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