Jump to content

Recommended Posts

Query:-

 

select
t . *, events.event_time as last_time
from
events,
(
(
	select
		bonding.type,
			bonding.global_id2 as target_post,
			bonding.target_id as on_whose_post,
			GROUP_CONCAT(bonding.shooter_id) as shooter_ids,
			GROUP_CONCAT(bonding.what_global_id) as shooted_what,
			MAX(bonding.what_global_id) as last,
			'bonding' as flag
	from
		bonding
	where
		bonding.type = 1
			and bonding.shooter_id in (select
				`user2`
			from
				relation_table
			where
				`user1` = 192)
	group by bonding.global_id2
)
union
(
select
		bonding.type,
			bonding.global_id2 as target_post,
			bonding.target_id as on_whose_post,
			GROUP_CONCAT(bonding.shooter_id) as shooter_ids,
			GROUP_CONCAT(bonding.what_global_id) as shooted_what,
			MAX(bonding.what_global_id) as last,
			'bonding' as flag
	from
		bonding
	where
		bonding.type = 2
			and bonding.shooter_id in (select
				`user2`
			from
				relation_table
			where
				`user1` = 192)
	group by bonding.global_id2
)
union
(
select
		bonding.type,
			bonding.global_id2 as target_post,
			bonding.target_id as on_whose_post,
			GROUP_CONCAT(bonding.shooter_id) as shooter_ids,
			GROUP_CONCAT(bonding.what_global_id) as shooted_what,
			MAX(bonding.what_global_id) as last,
			'bonding' as flag
	from
		bonding
	where
		bonding.type = 5
			and bonding.shooter_id in (select
				`user2`
			from
				relation_table
			where
				`user1` = 192)
	group by bonding.global_id2
)
union
(
select
		bonding.type,
			bonding.global_id2 as target_post,
			bonding.target_id as on_whose_post,
			GROUP_CONCAT(bonding.shooter_id) as shooter_ids,
			GROUP_CONCAT(bonding.what_global_id) as shooted_what,
			MAX(bonding.what_global_id) as last,
			'bonding' as flag
	from
		bonding
	where
		bonding.type = 9
			and bonding.shooter_id in (select
				`user2`
			from
				relation_table
			where
				`user1` = 192)
	group by bonding.global_id2
)
union
(
select
		bonding.type,
			bonding.global_id2 as target_post,
			bonding.target_id as on_whose_post,
			GROUP_CONCAT(bonding.shooter_id) as shooter_ids,
			GROUP_CONCAT(bonding.what_global_id) as shooted_what,
			MAX(bonding.what_global_id) as last,
			'bonding' as flag
	from
		bonding
	where
		bonding.type = 10
			and bonding.shooter_id in (select
				`user2`
			from
				relation_table
			where
				`user1` = 192)
	group by bonding.global_id2
)

)as t where events.global_id = t1.last

 

databse structure is given here

EVENTS-

 `global_id` int(11) NOT NULL AUTO_INCREMENT,
`event_creator` int(11) NOT NULL,
`event_type` int(2) NOT NULL,
`event_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`global_id`)

 

bonding:-


`shooter_id` int(12) NOT NULL COMMENT 'id of person who did something',
`type` int(4) NOT NULL COMMENT '1:news share; 2:photo share; 5:comment; 10:red flag; 9:green flag',
`what_global_id` int(12) NOT NULL COMMENT 'global id of event which is done',
`global_id2` int(12) NOT NULL COMMENT 'global id on which it is done',
`target_id` int(12) NOT NULL

Edited by manishk3008
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.