Jump to content

Help with a subquery join order by problem


matchoo

Recommended Posts

Hey. Never claimed to be a SQL expert, so here we are... first the query, then the problem.

 

It's a database about video clips.

 

Query looks like this...

 

SELECT engagementIndex,uniques FROM ts_clip_beacon_day LEFT JOIN  ts_clip_view_day ON ts_clip_beacon_day.clipXid = ts_clip_view_day.clipXid WHERE ts_clip_view_day.clipXid <> '+'

  AND ts_clip_view_day.year = 2007

  AND ts_clip_view_day.dayofyear = 304

  ORDER BY engagementIndex DESC

  LIMIT 200

 

So, this works, but it's not really what I want. This gives me the top 200 by engagement. What I want is the top 200 by UNIQUES which is in ts_clip_view_day but sorted (ORDERED) by engagementIndex which is in ts_clip_beacon_day

 

I'm sure it's simple... but I'm having brain farts.  Anyone... anyone... bueller?

Link to comment
Share on other sites

Hi,

 

I guess that your "clip_beacon" table may have more than one "clip_view". You are selecting from "clip_beacon", so you will get no more than one random "clip_view" for a given "clip_beacon". Try to replace FROM and JOIN tables to select from ts_clip_view_day and let me know if a result is like you want.

 

Michal

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.