Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql select query for getting user and follower's posts
    primarykey
    data
    text
    <p>Here is my select query statement:</p> <pre><code>select distinct posts.*, user_status.status_content from posts left join user_status on user_status.user_id = posts.user_id where posts.user_id = $userid or posts.user_id in (select follower from follower where follower.user_id = $userid) order by posts.created_at desc; </code></pre> <p>my select query statement works fine, except that the output is not what I exactly want. what I want is select all post from the current user and his followings, and each posts's user name is their latest <code>status content</code>, the status is updated by user, I want select only the latest status content from the table, so how can i do?</p> <p>posts table:</p> <pre><code>+------------+------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+------------+------+-----+---------+----------------+ | id | bigint(20) | NO | PRI | NULL | auto_increment | | user_id | bigint(20) | NO | MUL | NULL | | | content | text | NO | | NULL | | | created_at | datetime | YES | | NULL | | +------------+------------+------+-----+---------+----------------+ </code></pre> <p>user_status table:</p> <pre><code>+----------------+--------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+-------------------+-------+ | user_id | bigint(20) | NO | MUL | NULL | | | status_content | varchar(225) | YES | | Hello World | | | created_date | timestamp | NO | | CURRENT_TIMESTAMP | | +----------------+--------------+------+-----+-------------------+-------+ </code></pre> <p>the user can update thier status, so there will be more than one record in the user_status table.</p> <p>my select query may output like this:</p> <pre><code>I feel like s**t today!!!! Hello world 2013-03-28 22:34:14 ----------------------------- I don't feel very good today Hello world 2013-03-28 22:34:14 </code></pre> <p>what I want is, suppose the <code>I feel like s**t today</code> is the latest status, so it should output like:</p> <pre><code> I feel like s**t today!!!! Hello world 2013-03-28 22:34:14 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload