php - 一个查询中有两种不同的帖子类型

标签 php mysql

我在数据库中有两个表:

帖子表

id|name|message|time

通知表

id|name|initiator|type|message|time

我想要的是两个输出两个表混合而不是一个接一个。

像这样:

Simon: Reebal want to be friends? 5 minutes ago
Reebal: Yeah sure. 4 minutes ago
Simon and Reebal are friends now (notification)
Reebal: How are you? 2 minutes ago
Simon: Fine and you? 1 minute ago

不是这样的:

Simon and Reebal are friends now (notification)
Simon: Reebal want to be friends? 5 minutes ago
Reebal: Yeah sure. 4 minutes ago
Reebal: How are you? 2 minutes ago
Simon: Fine and you? 1 minute ago

这有可能吗?我希望你明白我的意思? 请不要提供完整的代码,只是对正确方法的建议。

最佳答案

建议:

您应该在两个查询中使用联合来获得结果。

UNION 关键字

关于php - 一个查询中有两种不同的帖子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45613511/

相关文章:

python - Django + MySQL,形成/创建 mysql 查询以将有效参数传递给 url

python - 如何让redis缓存和mysql的数据保持一致?

php - 使用Zend Gdata Youtube API获取视频上传日期

php - 只获取一个词后接下来的 6 个字符

mysql - 一个全栈网站需要运行多少个 NodeJS 项目?

php - mysql_fetch_array() 带有奇怪的输出

MySQL 条件列响应

php - mysql_insert_id() 的行为

PHP 编译时间与运行时间。了解差异

php - 使用 php 在同一页面中显示输出