在具有特定值的行之后选择行 [英] Select rows after a row with a certain value

查看:91
本文介绍了在具有特定值的行之后选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再次,我仍然遇到大量查询和问题,因此请原谅所有常见的sql问题8)

Hey again, im still getting a hang of Queries and stuff so please excuse all the frequent sql questions 8)

无论如何,我都会尝试在某个值之后选择行. 听不懂?好的,这就是它的外观.

Anyways im trying to select rows after a certain value. Dont understand? Ok this is how it actually looks.

表:消息

+------------+-----------+---------+-------+---------------------------------------+----------------+------------------+
| message_id | thread_id | user_id | to_id | body                                  | message_status | uid_sent_deleted |
+------------+-----------+---------+-------+---------------------------------------+----------------+------------------+
|          1 |         1 |       1 |     7 | How are you bro?                      | read           |                1 |
|          2 |         1 |       7 |     1 | IM good what about you kenny?         | read           |                0 |
|          3 |         1 |       1 |     7 | Same just chilling how is your sister | read           |                1 |
|          4 |         1 |       7 |     1 | Shes coool u know just doin great     | read           |                0 |
|          7 |         1 |       1 |     7 | Thats nice                            | read           |                1 |
|          8 |         1 |       7 |     1 | Yupp                                  | read           |                0 |
|          9 |         1 |       1 |     7 | hhahaha                               | read           |                1 |
|         10 |         1 |       7 |     1 | anyways....                           | unread         |                0 |
+------------+-----------+---------+-------+---------------------------------------+----------------+------------------+

其中消息ID为9的消息在uid_sent_deleted列中的值为"1". 我试图在uid_sent_deleted列中最后一行为'1'的行之后选择行.

Where the message id is 9, is has the value of '1' in the column uid_sent_deleted. Im trying to select rows after the last row that has a value of '1' in the column uid_sent_deleted.

这是我当前正在使用的sql.感谢您的帮助!

here is the sql that im currently working with. Thanks for the help!!

SELECT message_id, thread_id, messages.user_id, to_id, body, message_status, uid_sent_deleted
FROM messages
INNER JOIN messages_thread ON messages_thread.id = messages.thread_id
WHERE thread_id =1
GROUP BY messages.message_id
ORDER BY message_id ASC 

推荐答案

... WHERE thread_id = 1 AND id > 
     (SELECT MAX(id) FROM messages WHERE uid_sent_deleted = 1)

这篇关于在具有特定值的行之后选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆