Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
子查询内的MySQL连接_Mysql_Inner Join - Fatal编程技术网

子查询内的MySQL连接

子查询内的MySQL连接,mysql,inner-join,Mysql,Inner Join,我有这个: # tab1 = Company # tab2 = Forms # tab3 = Filled forms from each company enabled to it. # Search Companies with pending/empty Forms. # Company #1 has 3 forms, all filled, not will be listed; # Company #2 has form 2 and 3, only form 2 is filled,

我有这个:

# tab1 = Company
# tab2 = Forms
# tab3 = Filled forms from each company enabled to it.

# Search Companies with pending/empty Forms.
# Company #1 has 3 forms, all filled, not will be listed;
# Company #2 has form 2 and 3, only form 2 is filled, so it will be listed;
# Company #3 has not form filled, so it will be listed;

SELECT company.*
FROM tab1 as company

WHERE (
  SELECT TRUE
  FROM tab2 AS forms

  # Join compatible company forms results/fills.
  # Itll join with company.id (that here not exists) and the forms.id (that exists)
  LEFT JOIN tab3 AS fills ON
    fills.id_tab1 = company.id AND
    fills.id_tab2 = forms.id

  # Itll filter forms that company have.
  # And will accept ONLY if none result is found, what mean "pending fill" on company.
  # I need just that.
  WHERE 
    FIND_IN_SET(forms.id, company.id_forms) AND
    fills.id IS NULL
)
我得到未知列
tab1.id

如何解决

我需要访问子查询内部的
tab1

更新#1-
实时示例

试试这段代码,逻辑是一样的

 SELECT tab1.* from tab1
        inner join tab3 ON  tab3.id_tab1 = tab1.id
    WHERE .....

你到底想做什么?考虑提供适当的DDL(和/或SqLFIDLE)和期望的结果集,而不是只说“试试这个”,解释它是如何解决这个问题的(如果它确实是这样,我认为它没有)。我只是尽我所能去解决这个问题,如果它不起作用的话,David Rodrigues会尝试其他的东西。如果您看到他的原始代码tab.2与逻辑完全不相关,那么如果tab1.id=tab3.id,那么在tab2上选择true就是多余的。