php - Get DISTINCT results in SQL statement and ORDER BY Random -
so i'm trying unique results every time , can't work properly.
the user have multiple entries in table want pull 2 unique entries no matter how many each user may have in table.
this shouldn't difficult. seems easier in mysql though it's non standard. anyway, have , still pulls multiple results. should not allow multiple mem_id's
should unique. right allows same mem_id
both results.
select media_id,mem_id battle_entries active='1' , mem_id!=".$mem_id." group media_id,mem_id order random() limit 2
edit:
---------------------------------------------------- | btl_id | mem_id | posted | media_id | active | ----------------------------------------------------
that table columns btl_id
bigserial
, mem_id
,media_id
, posted
bigint
, active smallint
there can multiple rows mem_id not unique because user has multiple entries. want pull 2 random unique rows mem_id retrieve media_id in select. hope clearer.
try this:
select * (select distinct on (mem_id) mem_id, media_id battle_entries active='1' , mem_id!=1) s order random() limit 2;
Comments
Post a Comment