Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7854233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:59:24+00:00 2026-06-02T19:59:24+00:00

I have a query with SELECT CASE statement that’s working fine: SELECT (CASE `t`.`is_combined`

  • 0

I have a query with “SELECT CASE” statement that’s working fine:

SELECT 
(CASE `t`.`is_combined` 
WHEN 0 
THEN `t`.`topic_id` 
ELSE `t`.`is_combined` 
END) AS`group_id`,
    SUM(`ctt`.`tm_download_status`) AS `is_downloaded`, 
    COUNT(`t`.`topic_id`) AS `group_topics_cnt`,
    (SUM(`ctt`.`tm_download_status`) = COUNT(`t`.`topic_id`)) AS `is_downloaded_group` 
    FROM (`catalog_topics` `t` LEFT JOIN `catalog_tracker_torrents` `ctt` ON((`ctt`.`topic_id` = `t`.`topic_id`))) 
    WHERE (`t`.`topic_id` != 0) 
    GROUP BY (`group_id`)

So, i want to create a similar trigger to update “cross” table:

DELIMITER $$ 
CREATE TRIGGER `tdg_ins_by_topics` AFTER INSERT ON `catalog_topics` FOR EACH ROW 
BEGIN
REPLACE INTO catalog_topics_downloaded_groups(
      SELECT (
              CASE `t`.`is_combined`
              WHEN 0
              THEN `t`.`topic_id`
              ELSE `t`.`is_combined`
              END
     ) AS `group_id` , 
SUM( `ctt`.`tm_download_status` ) AS `is_downloaded` , 
COUNT( `t`.`topic_id` ) AS `group_topics_cnt` , (
SUM( `ctt`.`tm_download_status` ) = COUNT( `t`.`topic_id` ) ) AS `is_downloaded_group`
FROM `catalog_topics` `t`
LEFT JOIN `catalog_tracker_torrents` `ctt` ON `ctt`.`topic_id` = `t`.`topic_id`
WHERE `t`.`topic_id`
IN (
NEW.`topic_id`
)
GROUP BY `group_id`
)
END ;
$$

But getting an error message:

“#”1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near ‘END’ at line 14

It’s look like that MySQL doesn’t understand difference between CASE in TRIGGER statement and CASE in SELECT statement. So, how i can fix this?

Thanks for the answers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:59:28+00:00Added an answer on June 2, 2026 at 7:59 pm

    I think you need to “end” your REPLACE statement with ; like you have to end all statements inside a TRIGGER or PROCEDURE/FUNCTION with a delimeter.

    That is why you change the DELIMETER to $$ .. so you can use ; to store the mysql default delimeter inside of the trigger code. (and end the create trigger statement with the changed $$ delimeter)

    DELIMITER $$ 
    CREATE TRIGGER `tdg_ins_by_topics` AFTER INSERT ON `catalog_topics` FOR EACH ROW 
    BEGIN
        REPLACE INTO catalog_topics_downloaded_groups(
              SELECT ( CASE `t`.`is_combined`
                       WHEN 0
                       THEN `t`.`topic_id`
                       ELSE `t`.`is_combined`
                       END
                     ) AS `group_id`, 
                     SUM(`ctt`.`tm_download_status`) AS `is_downloaded`, 
                     COUNT( `t`.`topic_id` ) AS `group_topics_cnt` , 
                     (
                     SUM( `ctt`.`tm_download_status` ) = COUNT( `t`.`topic_id` ) ) AS `is_downloaded_group`
              FROM `catalog_topics` `t`
              LEFT JOIN `catalog_tracker_torrents` `ctt` ON `ctt`.`topic_id` = `t`.`topic_id`
              WHERE `t`.`topic_id` IN ( NEW.`topic_id` )
              GROUP BY `group_id`
        );
    END;
    $$
    DELIMETER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SQL query select case when AllowanceId is null then 2 else
I have a SELECT CASE statement that I am trying to get working. Essentially
I have a SQL statement that is something like this SELECT t1.* CASE WHEN
i have this query that works fine SELECT t.username FROM users t LEFT JOIN
Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
I have a problem in my select statement in my query. This sql query
I have this mysql query using PHP and first part is working fine, but
I have a query like this: SELECT A, B, C, CASE WHEN 1 =
I have the following query SELECT * FROM( SELECT CASE WHEN TO_CHAR (ADD_MONTHS(:DATEINPUT, 1),
SQL 2008 / 2005 I have SQL Query Syntax issue on Case Statement -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.