Tag Archives: Every derived table must have its own alias

sql Error: Every derived table must have its own alias [How to Solve]

Mysql database is used

 1 UPDATE tb_cr_circulate_gtsc 
 2 set path_status='A06'
 3 where
 4 order_id='Ph800601211123155507'
 5 and
 6 receive_role='21075116-001'
 7 and
 8 receive_role_name='024722cd-b197-462f-bdc2-f0423d88e580&Z&11caea25-4996-4682-aa3c-ea698e5140cc&21075116-001&四川省川东农药化工有限公司'
 9 and 
10 ( 
11 (SELECT statusSum from   (select COUNT(path_status)  as statusSum FROM tb_cr_circulate_gtsc  where order_id='Ph800601211123155507' and path_status='A04' and is_current_point='1' ) )
12 <  
13 (SELECT statusSum from  (select COUNT(path_status)  as statusSum  FROM tb_cr_circulate_gtsc where order_id='Ph800601211123155507' and is_current_point='1') )
14 )

Error message: each derived table must have its own alias

Solution: add an alias to the newly generated table

1 ( 
2 (SELECT statusSum from   (select COUNT(path_status)  as statusSum FROM tb_cr_circulate_gtsc  where order_id='Ph800601211123155507' and path_status='A04' and is_current_point='1' ) as a)
3 <  
4 (SELECT statusSum from  (select COUNT(path_status)  as statusSum  FROM tb_cr_circulate_gtsc where order_id='Ph800601211123155507' and is_current_point='1') as a )
5 )

Every derived table must have its own alias

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

Background: the error of every derived table must have its own alias occurs during the query of linked tables

Error code:

        SELECT t1.id FROM zhfw_service_reply t1
        JOIN(
        SELECT id FROM zhfw_service_theme t3  WHERE
        updated_time &lt; #{time}
        AND section_code = 'service'
        ) on t3.id = t1.theme_id

Cause: the alias of the table was omitted. Query to generate new tables every derived table must have its own alias . That is, the result of the join needs a new name. Replace with the following:

        SELECT t1.id FROM zhfw_service_reply t1
        JOIN(
        SELECT id FROM zhfw_service_theme  WHERE
        updated_time &lt; #{time}
        AND section_code = 'service'
        )t3 on t3.id = t1.theme_id

Note the location of T3