This is my query
select
users.id as user_id,
users.cat as cat,
from_currencies.id as from_currency,
to_currencies.id as to_currency,
deals_public.change_from as change_from,
deals_public.change_to as change_to,
users.site as link,
users.username as user_name,
users.email as email,
users.active as active,
from_currencies.name as from_name,
from_currencies.sign as from_sign,
to_currencies.name as to_name,
to_currencies.sign as to_sign
from
`deals_public`
inner join `users` on `users`.`id` = `deals_public`.`user_id`
inner join `currencies` as `from_currencies` on `from_currencies`.`id` = `deals_public`.`from_currency`
inner join `currencies` as `to_currencies` on `to_currencies`.`id` = `deals_public`.`to_currency`
where
`users`.`active` = 1
and from_currency like '34'
and to_currency like '35'
limit
20
I have a column in deals_public
table named register
that holds created_at
timestamp, and I want to get the latest row based on user_id
.
I mean I want to get only one record from deals_public for each user_id
EDIT:
I got this working by using:
group by user_id
but this query is taking too long(15 seconds)
how can I reduce this time??