MySQL Union always returns one row with NULL's -
given following query…
select distinct * pas_post post_user_id = 21 group post_post_id union select distinct pas_post.* pas_follow left join pas_post on ( pas_follow.folw_followed_user_id = pas_post.post_user_id ) pas_follow.folw_follower_user_id = 21 group post_post_id order post_posted_date desc i row in results null's, unfortunately need preserve null values in data post's table (pas_post) holds different types of information.
can steer me in right direction rid of null row.

i not want or need last row here
you're using (left) outer join in second part of union, cases not satisfy join criteria result in data table on left of join (pas_follow), null in every column of table on right of join (pas_post); subsequent selection of columns latter table results in null rows observe. therefore, simplest solution use inner join (that excludes records join criteria not met).
however, in case, appears query can simplified using 2 possible conditions in filter on joined tables rather union:
select p.* pas_post p join pas_follow f on f.folw_followed_user_id = p.post_user_id p.post_user_id = 21 or f.folw_follower_user_id = 21 order p.post_posted_date desc i have excluded group by clause on assumption post_post_id primary key (or @ least unique) in pas_post table. if assumption incorrect, may want reintroduce it—but beware mysql indeterminately select values returned each group.
Comments
Post a Comment