Skip to content

Instantly share code, notes, and snippets.

@vetalt
Created February 17, 2016 20:01
Show Gist options
  • Save vetalt/1457b59840a22cc8af49 to your computer and use it in GitHub Desktop.
Save vetalt/1457b59840a22cc8af49 to your computer and use it in GitHub Desktop.
getLatestForCategories
select
ft1.parent_category_id,
substring_index(group_concat(ft1.forum_topic_id order by ft1.last_forum_topic_create_date desc), ',', 3) as ids
from
forum_topic ft1
join user u1 on ft1.user_id = u1.user_id
and u1.is_content_hidden = 0
join forum_topic ft2 on ft1.last_forum_topic_id = ft2.forum_topic_id
join user u2 on ft2.user_id = u2.user_id
and u2.is_content_hidden = 0
and (
u2.main_image_hash is not null
or u2.create_date < date_sub(curdate(), interval 30 day)
)
where
ft1.parent_category_id is not null
and ft1.is_parent_topic = 1
and ft1.post_count > 3
and ft1.is_live = 1
group by
ft1.parent_category_id
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
select
ft.parent_category_id,
ft.forum_topic_id,
ft.subject,
ft.url,
ft.post_count,
ft.last_forum_topic_create_date,
case when ft.is_locked then 'locked' when tft.track_forum_topic_id is not null then 'tracked' else 'none' end as status,
if (
ft.create_date >= ifnull('2016-02-17 11:23:32', date_sub(curdate(), interval 7 day))
and ft.forum_topic_id not in (0), 1, 0) as new
from
forum_topic ft
left join track_forum_topic tft on ft.forum_topic_id = tft.forum_topic_id
and tft.user_id = ifnull(41, 0)
where
ft.forum_topic_id in ('23', '415', '2835', '2815', '20', '279', '202', '481', '1543', '764', '292')
order by
ft.last_forum_topic_create_date desc
@jseverson
Copy link

(select 
  ft.*
from 
  forum_topic ft
where 
  ft.parent_category_id  = 1
  and ft.is_parent_topic = 1 
  and ft.post_count > 3 
  and ft.is_live = 1
  and ft.is_sticky = 0
  and ft.forum_topic_type_id = 1
order by
    ft.last_forum_topic_create_date desc
limit 3)
union
(select 
  ft.*
from 
  forum_topic ft
where 
  ft.parent_category_id  = 3
  and ft.is_parent_topic = 1 
  and ft.post_count > 3 
  and ft.is_live = 1
  and ft.is_sticky = 0
  and ft.forum_topic_type_id = 1
order by
    ft.last_forum_topic_create_date desc
limit 3)
union
(select 
  ft.*
from 
  forum_topic ft
where 
  ft.parent_category_id  = 4
  and ft.is_parent_topic = 1 
  and ft.post_count > 3 
  and ft.is_live = 1
  and ft.is_sticky = 0
  and ft.forum_topic_type_id = 1
order by
    ft.last_forum_topic_create_date desc
limit 3)
union
(select 
  ft.*
from 
  forum_topic ft
where 
  ft.parent_category_id  = 5
  and ft.is_parent_topic = 1 
  and ft.post_count > 3 
  and ft.is_live = 1
  and ft.is_sticky = 0
  and ft.forum_topic_type_id = 1
order by
    ft.last_forum_topic_create_date desc
limit 3)
union
(select 
  ft.*
from 
  forum_topic ft
where 
  ft.parent_category_id  = 6
  and ft.is_parent_topic = 1 
  and ft.post_count > 3 
  and ft.is_live = 1
  and ft.is_sticky = 0
  and ft.forum_topic_type_id = 1
order by
    ft.last_forum_topic_create_date desc
limit 3)
union
(select 
  ft.*
from 
  forum_topic ft
where 
  ft.parent_category_id  = 7
  and ft.is_parent_topic = 1 
  and ft.post_count > 3 
  and ft.is_live = 1
  and ft.is_sticky = 0
  and ft.forum_topic_type_id = 1
order by
    ft.last_forum_topic_create_date desc
limit 3)
union
(select 
  ft.*
from 
  forum_topic ft
where 
  ft.parent_category_id  = 9
  and ft.is_parent_topic = 1 
  and ft.post_count > 3 
  and ft.is_live = 1
  and ft.is_sticky = 0
  and ft.forum_topic_type_id = 1
order by
    ft.last_forum_topic_create_date desc
limit 3)
union
(select 
  ft.*
from 
  forum_topic ft
where 
  ft.parent_category_id  = 10
  and ft.is_parent_topic = 1 
  and ft.post_count > 3 
  and ft.is_live = 1
  and ft.is_sticky = 0
  and ft.forum_topic_type_id = 1
order by
    ft.last_forum_topic_create_date desc
limit 3)
union
(select 
  ft.*
from 
  forum_topic ft
where 
  ft.parent_category_id  = 11
  and ft.is_parent_topic = 1 
  and ft.post_count > 3 
  and ft.is_live = 1
  and ft.is_sticky = 0
  and ft.forum_topic_type_id = 1
order by
    ft.last_forum_topic_create_date desc
limit 3);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment