首页 \ 问答 \ 在一个查询中加入/查看Mysql中的三个表(Join/Look In Mysql Three Tables In One Query)

在一个查询中加入/查看Mysql中的三个表(Join/Look In Mysql Three Tables In One Query)

我决定创建人们你可能知道的系统,但我已经解决了一个问题,似乎我需要加入三个表来带来相关的结果。

目的是在数据库表中检查可能根据我朋友的朋友知道的朋友(if user1 = user2 and user2 = user4 posibile user1 knows user4, user4 is a suggestion)我使用以下代码来检查这个并且是按计划工作。

SELECT `friendpin` AS `possible_friend_id`
FROM `pinme`
WHERE `senderpin`
IN (
SELECT `friendpin`
FROM `pinme`
WHERE `senderpin` = $userlogged
)
AND `friendpin` NOT
IN (

SELECT `friendpin`
FROM `pinme`
WHERE `senderpin` = $userlogged
)
AND NOT `friendpin` = $userlogged
GROUP BY `possible_friend_id`
ORDER BY COUNT( * ) DESC
LIMIT 0 , 3 

因此, REQUEST表中的建议人员状态可能已经向您提出待处理请求,但仍然显示为建议的朋友,或者在BLOCKED表中,建议的朋友被阻止但仍然显示给您作为建议的朋友。 因此我想消除这种行为。 建议的人不应该在REQUEST表或BLOCKED表中退出。

谁能帮我解决这个问题?

以下是REQUEST表, PINME表和BLOCKED表结构

REQUEST TABLE:
senderpin - id of the person who send request   
friendpin - receivers request id    


BLOCKED TABLE: 
user1_id - a person who block user2_id
user2_id - the blocked person by user1_id


PINME TABLE:
PINME table: the table which keep relations
structure: 1,2 2,2 | 4,8 8,4
senderpin - id of the person who send request   
friendpin - receivers request id

感谢致敬


I decided to create People You May Know System but i have accounted a problem where it seems I need to join three tables to bring relevant results.

The aim is to check in database table for possible friends one may know based on friend of my friend (if user1 = user2 and user2 = user4 posibile user1 knows user4, user4 is a suggestion) I have used the following code to check this and is working as to plan.

SELECT `friendpin` AS `possible_friend_id`
FROM `pinme`
WHERE `senderpin`
IN (
SELECT `friendpin`
FROM `pinme`
WHERE `senderpin` = $userlogged
)
AND `friendpin` NOT
IN (

SELECT `friendpin`
FROM `pinme`
WHERE `senderpin` = $userlogged
)
AND NOT `friendpin` = $userlogged
GROUP BY `possible_friend_id`
ORDER BY COUNT( * ) DESC
LIMIT 0 , 3 

Thus its possible that the suggested person status in REQUEST table he/she has already a request pending to you but still being shown as suggested friend or in the BLOCKED table the suggested friend was blocked but still appear to you as suggested friend. therefore I would like to eliminate this behavior. a suggested person should not be exits either in REQUEST table or BLOCKED table.

Can anyone help me solve this?

the following are the REQUEST table, PINME table and BLOCKED table structure

REQUEST TABLE:
senderpin - id of the person who send request   
friendpin - receivers request id    


BLOCKED TABLE: 
user1_id - a person who block user2_id
user2_id - the blocked person by user1_id


PINME TABLE:
PINME table: the table which keep relations
structure: 1,2 2,2 | 4,8 8,4
senderpin - id of the person who send request   
friendpin - receivers request id

Thanks and regards


原文:https://stackoverflow.com/questions/17399624
更新时间:2023-10-27 20:10

最满意答案

像这样定义它:

function mytheme_preprocess_page(&$variables, $hook = null) {

使hook参数可选,然后你可以调用这样的函数:

mytheme_preprocess_page($var);mytheme_preprocess_page($var, $another_var)

在第一种情况下, $hook将为null ,在第二种$hook中将具有$another_var的值

您可以像这样检查您的函数: if ($hook === null) {调用两者中的哪一个


defining it like this:

function mytheme_preprocess_page(&$variables, $hook = null) {

Makes the hook parameter optional, you then can call the function like this:

mytheme_preprocess_page($var); or mytheme_preprocess_page($var, $another_var).

In the first case $hook will be null, in the second $hook will have the value of $another_var

You can check in your function like this: if ($hook === null) { Which of the two is called

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)