MYSQL:子子查询

时间:2014-08-07 01:21:17

标签: mysql subquery

这将返回超过200行

 SELECT 
 distinct FN.field_first_name_value, 
 LN.field_last_name_value,   
 u.mail,
 IFNULL(
  (SELECT 'yes'
       FROM users_roles SUR1
    WHERE SUR1.uid = u.uid
      AND SUR1.rid = 4
    LIMIT 1
  )
 ,'No') AS 'Paying Member',
 IFNULL(
  (SELECT 'Yes'
       FROM users_roles SUR
    WHERE SUR.uid = u.uid
      AND SUR.rid = 10
    LIMIT 1
  )
 ,'No') AS 'Newsletter Subscriber'
 FROM
 users u, 
 field_data_field_first_name FN, 
 field_data_field_last_name LN, 
 role R,
 users_roles SUR
 where 
 u.uid = FN.entity_id 
 AND 
 u.uid = LN.entity_id

但这只返回30。

SELECT 
distinct FN.field_first_name_value, 
LN.field_last_name_value,   
u.mail,
IFNULL(
     (SELECT (
        select distinct
     CASE
         WHEN status = 4 THEN "Expiring Soon" 
         WHEN status = 3 THEN "Active Payments Complete" 
         WHEN status = 0 THEN "Expired / Inactive"
         WHEN status = 2 THEN "Cancelled" 
     END AS status
        FROM scio_ms_memberships smm
        where u.uid = smm.uid
     )
          FROM scio_users_roles SUR1
       WHERE SUR1.uid = u.uid
         AND SUR1.rid = 4
       LIMIT 1
     )
   ,'No') AS 'Paying Member',
IFNULL(
     (SELECT 'Yes'
          FROM scio_users_roles SUR
       WHERE SUR.uid = u.uid
         AND SUR.rid = 10
       LIMIT 1
     )
   ,'No') AS 'Newsletter Subscriber'
FROM
scio_users u, 
scio_field_data_field_first_name FN, 
scio_field_data_field_last_name LN, 
scio_role R,
scio_users_roles SUR
where 
u.uid = FN.entity_id 
AND 
u.uid = LN.entity_id

这是为什么? 它确实有子子选择

(
 select distinct
     CASE
         WHEN status = 4 THEN "Expiring Soon" 
         WHEN status = 3 THEN "Active Payments Complete" 
         WHEN status = 0 THEN "Expired / Inactive"
         WHEN status = 2 THEN "Cancelled" 
     END AS status
        FROM scio_ms_memberships smm
        where u.uid = smm.uid
)

但是我无法理解为什么会这么影响它。

为什么行数存在差异?

MYSQL还告诉我“此表格不包含唯一列。网格编辑,复选框,编辑,复制和删除功能不可用。

显示行0 - -1(总计0,查询耗时0.0398秒)“

0 个答案:

没有答案