On Apr 25, 6:35 pm, Scott Kulik <li...@ruby-forum.com> wrote: > Frederick Cheung wrote: > > On Apr 25, 1:57 am, Scott Kulik <li...@ruby-forum.com> wrote: > >> updating the database when a users has problems with their private > >> messages page. > > >> I'm wondering if someone knows a good way I could scan the the pm's > >> table and delete messages that no longer have a user for sent_to or > >> sent_from. > > > sounds like a job for a left join. If I were you I'd also setup a > > foreign key constraint so that this sort of thing can't happen in the > > future > > > Fred > > Thanks Fred. The problem is i don't know the syntax for the join. Did > you happen to know off the top of your head?
I very highly reccomend learning that sort of stuff. select * from foos left join bars on foos.id =bars.foo_id Will join rows from foos with rows form bars. Unlike an inner join (where no rows are returned if there is no bar satisfying the condition for a given foo) with a left join such foos will result in a row being returned, with all the columns for bars being null, so you just need to have a IS NULL condition on a column that cannot be null (eg bars.id) to find all foos with no associated bar. Fred > -- > Posted viahttp://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-t...@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/rubyonrails-talk?hl=en. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.