0

I get the following error while running this query:

#1241 - Operand should contain 1 column(s)

SELECT *,
       Date_format(date_assigned, '%d-%m-%y')                     AS datum,
       YEAR(date_assigned)                                        AS YEAR,
       YEAR(NOW())                                                AS this_year,
       Datediff(NOW(), date_assigned)                             AS age,
       MONTH(NOW())                                               AS this_month,
       Concat(Period_add(Date_format(date_released, "%Y%m"), -6)) AS cancel_date
       ,
       Date_format(NOW(), '%Y%m')                                 AS
       this_date
FROM   reseller_numbers
WHERE  reseller_id = '31'
       AND MONTH(date_assigned) = '12'
       AND ( ( date_released IS NULL
                OR date_released > NOW() )
              OR ( Dayofyear(date_assigned) <= Dayofyear(date_released)
                   AND ( date_released IS NULL
                          OR date_released > NOW() ) ) )
       AND ( date_released IS NULL
              OR date_released > NOW()
                 AND date_released NOT LIKE '%2999%'
                 AND date_released != '2038-01-01 00:00:00' )
       AND ( date_released NOT IN (SELECT *,
                                          Date_format(DATE_ADD(date_released,
                                                      INTERVAL '-6' MONTH),
                                          '%d%m%y')
                                          AS
                                          cancel_date
                                   FROM   reseller_numbers
                                   WHERE  reseller_id = '31'
                                   HAVING DATE_ADD(date_released,
                                          INTERVAL '-6' MONTH)
                                          <
                                          NOW(
                                          )) )
ORDER  BY date_released DESC
LIMIT  0, 30 

Is there something wrong with this query? When I remove the subquery in date_released NOT IN, the query executes just fine.

4 Answers 4

2

The sub query must return only a single column for the date_released value to match on. Get rid of the "*,"

Sign up to request clarification or add additional context in comments.

Comments

1

in date_released you should only select one column

SELECT Date_format(DATE_ADD(date_released,
                                                  INTERVAL '-6' MONTH),
                                      '%d%m%y')
                                      AS
                                      cancel_date
                               FROM   reseller_numbers
                               WHERE  reseller_id = '31'
                               HAVING DATE_ADD(date_released,
                                      INTERVAL '-6' MONTH)
                                      <
                                      NOW(
                                      ))

Comments

1

remove * from subquery

SELECT *,
       Date_format(date_assigned, '%d-%m-%y')                     AS datum,
       YEAR(date_assigned)                                        AS YEAR,
       YEAR(NOW())                                                AS this_year,
       Datediff(NOW(), date_assigned)                             AS age,
       MONTH(NOW())                                               AS this_month,
       Concat(Period_add(Date_format(date_released, "%Y%m"), -6)) AS cancel_date
       ,
       Date_format(NOW(), '%Y%m')                                 AS
       this_date
FROM   reseller_numbers
WHERE  reseller_id = '31'
       AND MONTH(date_assigned) = '12'
       AND ( ( date_released IS NULL
                OR date_released > NOW() )
              OR ( Dayofyear(date_assigned) <= Dayofyear(date_released)
                   AND ( date_released IS NULL
                          OR date_released > NOW() ) ) )
       AND ( date_released IS NULL
              OR date_released > NOW()
                 AND date_released NOT LIKE '%2999%'
                 AND date_released != '2038-01-01 00:00:00' )
       AND ( date_released NOT IN (SELECT Date_format(DATE_ADD(date_released,
                                                      INTERVAL '-6' MONTH),
                                          '%d%m%y')
                                          AS
                                          cancel_date
                                   FROM   reseller_numbers
                                   WHERE  reseller_id = '31'
                                   HAVING DATE_ADD(date_released,
                                          INTERVAL '-6' MONTH)
                                          <
                                          NOW(
                                          )) )
ORDER  BY date_released DESC
LIMIT  0, 30 

Comments

0

The subquery must have only one value selected, probably the DATE_FORMAT one. Remove the *.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.