Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Problem with my query that has a join and ordered by a max
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
desbest  
View profile  
 More options Oct 20 2012, 6:44 pm
From: desbest <afanintheho...@gmail.com>
Date: Sat, 20 Oct 2012 15:44:00 -0700 (PDT)
Subject: Problem with my query that has a join and ordered by a max

I'm having problems with this query, which I've put on Github Gist for
syntax highlighting so you can see what's going on better.

What I want to do, is join the groups table to the posts table, which I've
done. But I only want to retreive the tables that have their pond column,
being more than 1.

The link is here.

https://gist.github.com/3925058


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Evans  
View profile  
 More options Oct 20 2012, 9:52 pm
From: Jeremy Evans <jeremyeva...@gmail.com>
Date: Sat, 20 Oct 2012 18:52:23 -0700 (PDT)
Local: Sat, Oct 20 2012 9:52 pm
Subject: Re: Problem with my query that has a join and ordered by a max

On Saturday, October 20, 2012 3:44:00 PM UTC-7, desbest wrote:

> I'm having problems with this query, which I've put on Github Gist for
> syntax highlighting so you can see what's going on better.

> What I want to do, is join the groups table to the posts table, which I've
> done. But I only want to retreive the tables that have their pond column,
> being more than 1.

> The link is here.

> https://gist.github.com/3925058

Your first error is "SQLite3::SQLException: no such column:
posts.datenumber", which should be obvious, that column doesn't exist in
that table.  You didn't post the schema for the tables involved in the
query, but if I had to guess, you want groups__datenumber instead of
posts__datenumber.

Your second error is "comparison of Symbol with Integer failed", which is
because you are on ruby 1.9 and Sequel doesn't override the Symbol#>
method. Use a virtual row, switch "exclude(:posts__pond > 0)" to
"exclude{posts__pond > 0}".

Jeremy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tynamite  
View profile  
 More options Oct 21 2012, 4:36 am
From: tynamite <afanintheho...@gmail.com>
Date: Sun, 21 Oct 2012 09:36:56 +0100
Local: Sun, Oct 21 2012 4:36 am
Subject: Re: Problem with my query that has a join and ordered by a max

For the first error, I would like to say that the posts.datenumber and
groups.datenumber column *does* exist. I probably should have made that
clear,
I've added the schema now. https://gist.github.com/3925058
When I use the virtual row, it started working to do what I wanted it to
do. Thank you. It was a query to order groups based on recent activity,
excluding comment replies.

This leads me to my 2nd question.

How can I modify the first query that originally worked, so that inbetween
.order{max(posts__datenumber) and .order_append(:groups__datenumber), that
posts with a pond with more than zero 0, be excluded from the ordering of
the rows, or that the groups with a post above zero, gets lower presedence
in sorting?

On 21 October 2012 02:52, Jeremy Evans <jeremyeva...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Evans  
View profile  
 More options Oct 21 2012, 12:08 pm
From: Jeremy Evans <jeremyeva...@gmail.com>
Date: Sun, 21 Oct 2012 09:08:48 -0700 (PDT)
Local: Sun, Oct 21 2012 12:08 pm
Subject: Re: Problem with my query that has a join and ordered by a max

You are joining to a subselect, which requires using an alias (Sequel
creates uses a default alias if you don't specify one), you probably want
"join(Post.where{floor > 0}.as(:posts), :group_id=>:id)".  The current code
fails because in the query, posts.datenumber is not valid.  Also, you
should probably remove the ".exclude()".

Note that you can call the sql method on any dataset to see the SQL it
would generate, which would make it more obvious why SQLite didn't like
your SQL.

Jeremy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tynamite  
View profile  
 More options Oct 21 2012, 3:28 pm
From: tynamite <afanintheho...@gmail.com>
Date: Sun, 21 Oct 2012 20:28:07 +0100
Local: Sun, Oct 21 2012 3:28 pm
Subject: Re: Problem with my query that has a join and ordered by a max

Thanks alot but that wasn't the answer I was looking for with my question
as I had changed my original sql query to be more specific.
Disregard my previous messages. Here's the completely new question.

I've improved my sql to

@groups = Group.where().group(:groups__id).left_join(:posts, :group_id=>:id)


.order(Sequel.desc(:groups__id))

.select(:groups__id, :groups__user_id, :groups__title)


What I would like to do, is order the groups on my website, based on
the *recent
activity* within those groups.
Right now *(in the query above)* the groups are ordered by their id column
in descending order.
I would like to improve this, by *also *ordering them by the latest post
made inside them, also sorted by a descending id column.

Here's what I tried to use that didn't work.

@groups = Group.where().group(:groups__id).left_join(:posts, :group_id=>:id)


.order(Sequel.desc(:groups__id))*.order_prepend{max(posts__datenumber)***

.select(:groups__id, :groups__user_id, :groups__title)


So far, that hasn't changed anything.
I created a row in the posts table, with the value of 1 for the group_id
column, and it hasn't done anything.
I would like to be matched up to the group's id of 1, and be used for
sorting those groups.

Could you please help?

On 21 October 2012 17:08, Jeremy Evans <jeremyeva...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tynamite  
View profile  
 More options Oct 21 2012, 4:21 pm
From: tynamite <afanintheho...@gmail.com>
Date: Sun, 21 Oct 2012 21:21:28 +0100
Local: Sun, Oct 21 2012 4:21 pm
Subject: Re: Problem with my query that has a join and ordered by a max

After enough time I managed to fix everything Jeremy and get the query I
want. Thanks for your help about using an alias to join to a subselect.

On 21 October 2012 20:28, tynamite <afanintheho...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »