首页 \ 问答 \ 消息传递mysql表查询(Messaging mysql table query)

消息传递mysql表查询(Messaging mysql table query)

我正在尝试实现一个消息传递系统,但略有不同。 消息只能从用户2启动到用户1.此启动消息具有start = 1值。

+---------+----------+----------+-----------+----- -----+-------+---------------------+
| id (ai) | user1id  | user2id  | originated| to_user2  | start | messag              | 
+---------+----------+----------+-----------+-----------+-------+---------------------+
| 1       |  1       | 2        |  1234     |    0      |   1   | Hi                  | 
| 2       |  1       | 2        |  1234     |    1      |   0   | Hi back             | 
| 3       |  1       | 2        |  1234     |    0      |   0   | So Whats up         | 
| 4       |  1       | 2        |  1234     |    1      |   0   | Nothing much, why   | 
| 5       |  1       | 2        |  1234     |    0      |   0   | Just checking       | 
| 6       |  1       | 2        |  1234     |    1      |   0   | OK                  | 
+---------+----------+----------+-----------+-----------+-------+---------------------+

所以我可以通过WHERE start ='1'来获取起始消息。

我能够从user1到user2获取做WHERE to_user2 ='1'的消息

通过执行WHERE to_user2 ='0'和start ='0',我能够从user2到user1获取消息

对? 跟着我?

我将如何进行查询以便获得以下输出:

STARTING MESSAGE  (id 1)
 message to user2  (id 2)          

              message to user 1  (id3)
              message to user 2  (id4)

                      message to user 1  (id5)
                      message to user 2  (id6)

我希望我有所作为。

让我澄清一下,我能够使用6个不同的查询获得此输出,但我想知道这是否可行,以及它是否可能在1个查询中。


I'm trying to implement a messaging system, but with a slight twist. Messages can only be started from user 2 to user 1. This starting message has the start = 1 value.

+---------+----------+----------+-----------+----- -----+-------+---------------------+
| id (ai) | user1id  | user2id  | originated| to_user2  | start | messag              | 
+---------+----------+----------+-----------+-----------+-------+---------------------+
| 1       |  1       | 2        |  1234     |    0      |   1   | Hi                  | 
| 2       |  1       | 2        |  1234     |    1      |   0   | Hi back             | 
| 3       |  1       | 2        |  1234     |    0      |   0   | So Whats up         | 
| 4       |  1       | 2        |  1234     |    1      |   0   | Nothing much, why   | 
| 5       |  1       | 2        |  1234     |    0      |   0   | Just checking       | 
| 6       |  1       | 2        |  1234     |    1      |   0   | OK                  | 
+---------+----------+----------+-----------+-----------+-------+---------------------+

So I'm able to get the starting message by doing WHERE start = '1'.

I'm able to get the messages from user1 to user2 doing WHERE to_user2 = '1'

I'm able to get the messages from user2 to user1 by doing WHERE to_user2 = '0' and start='0'

Right? following me?

How would I make my query so that I get the following output:

STARTING MESSAGE  (id 1)
 message to user2  (id 2)          

              message to user 1  (id3)
              message to user 2  (id4)

                      message to user 1  (id5)
                      message to user 2  (id6)

I hope im making some sense.

Let me clarify that im able to get this output using 6 different querys, but i wonder if thats the way to go, and if its possible in 1 query.


原文:https://stackoverflow.com/questions/17132463
更新时间:2023-03-15 14:03

最满意答案

描述的值没有定义,你应该首先检查:

 if (location.description && location.description.length < minLocationLength) {
          reject(`Location must be at least ${minLocationLength} characters.`);
        }

The value of description is not defined, you shall check like this first:

 if (location.description && location.description.length < minLocationLength) {
          reject(`Location must be at least ${minLocationLength} characters.`);
        }

相关问答

更多
  • 对于支持Object.keys()的浏览器,您可以简单地做: Object.keys(a).length; 否则(特别是在IE <9)中,您可以使用for (x in y)循环自己循环遍历对象: var count = 0; var i; for (i in a) { if (a.hasOwnProperty(i)) { count++; } } hasOwnProperty是确保您只是从对象字面值计算属性,而不是从其原型“继承”的属性。 For browsers su ...
  • 最强大的答案(即捕获你想要做的事情,同时造成最少的错误)是: Object.size = function(obj) { var size = 0, key; for (key in obj) { if (obj.hasOwnProperty(key)) size++; } return size; }; // Get the size of an object var size = Object.size(myArray); JavaScript中有一种 ...
  • 描述的值没有定义,你应该首先检查: if (location.description && location.description.length < minLocationLength) { reject(`Location must be at least ${minLocationLength} characters.`); } The value of description is not defined, you shall check like this ...
  • 这有很多问题: len = 3 d = Array.new t = File.open('d.txt').read t.each_line do |x| #+2 accounting for \n\r if x.length == (len + 2) d.push(x) end end 首先,由于File.open('d.txt').read整个文件到内存中,然后使用each_line分割成行,最后捕获所需长度的行。 如果文件由1,000,000行组成,并且只有一行 ...
  • 这将返回werte中的一系列条目; var rowCount = []; for(var i=0;i
  • 使用Object.keys(obj).length来获取Object的长度 var tiles = { tile1 : { header : "header1", desc : "desc1" }, tile2 : { header : "header2", desc : "desc2" } }; console.log(Object.key ...
  • 在你发布的java代码的C#中绝对有一个简单的等价物。 实际上,您目前正在使用的C#版本使用异步调用,这比对流的简单调用要复杂得多。 如果你想在没有异步调用的情况下在C#中使用缓冲流,你可以只Read流。 一样容易: socket.InputStream.Read() 在您的Java代码中,您似乎使用大小为100的缓冲区来读取流。 您只读取了100个字节的流,而不是一直到最后。 如果这是你想要的,你可以做: byte[] b = new byte[100]; int readTo = socket.Inp ...
  • 我们可以将'a'中的每个元素复制为'b'的length除以'b',转换为matrix并获得列总和( colSums ) colSums(matrix(b/rep(a, each=length(b)), ncol=8)) #[1] 1650.0000 1237.5000 990.0000 825.0000 707.1429 618.7500 550.0000 #[8] 495.0000 或者我们遍历'a'的每个元素,除以'b',得到sum 。 sapply(a, function(x) s ...
  • 听起来你有一些针对你的代码运行的自动测试,他们正在检查你如何处理错误的输入。 您的代码未设置为处理除预期数字数组以外的任何内容,因此它无法通过这些测试。 你可以通过很多方式解决这个问题,但这很简单 if (input === null) { return 'Input invalid'; // or something like that } // put your for loop here 会做的伎俩。 有可能,您可能会面临更多需要处理意外输入的测试用例。 我希望这有帮助。 It sounds ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。