douzhiji2020
2013-12-07 07:38
浏览 19

管理sql中具有多行的子查询

Im doing this small twitter page and I want to query my tweets some how.
Id like them to have those @(eg. "@someName") signs and when someone follows someone, their tweets will be displayed.
PHP QUERY:

    SELECT * from tweetsTab where username = '".$user."' or username = (SELECT
    followed from followTab where follower = '".$user."') or tweet like CONCAT
    ('%@', (SELECT followed from followTab where follower = '".$user."'), '%') or
    tweet like '%@".$user."%' ORDER BY tweetTime DESC;

The subqueries have multible rows which is an error. So im Kinda stuck here and a beginner to SQL.

So how can I query when subquery has multible rows and " IN " doesn't work, so that I can keep sorting by tweetTime

图片转代码服务由CSDN问答提供 功能建议

我正在做这个小推特页面,我想查询我的推文。
他们喜欢他们有@(例如“@someName”)标志,当有人跟随某人时,会显示他们的推文。
非常任务:

 来自tweetsTab的SELECT *,其中username ='“。$ user。”'或者用户名=(SELECT 
后跟followTab,其中follower ='  “。$ user。”')或推文如CONCAT 
('%@',(SELECT跟随followTab where follower ='“。$ user。”'),'%')或
鸣叫如'%@  “。$ user。”%'ORDER BY tweetTime DESC; 
   
 
 

子查询具有多行,这是一个错误。 所以我有点被困在这里,并且是SQL的初学者。

那么如何查询子查询何时具有多行并且“IN”不起作用,以便我可以通过tweetTime继续排序< / p>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpvr49226 2013-12-07 07:49
    已采纳

    You can use IN

    SELECT * from tweetsTab where username = '".$user."' or username IN (SELECT
    followed from followTab where follower = '".$user."') or tweet like CONCAT
    ('%@', (SELECT followed from followTab where follower = '".$user."'), '%') or
    tweet like '%@".$user."%' ORDER BY tweetTime DESC;
    
    点赞 评论

相关推荐 更多相似问题