sql语句 异常 Err] 1064 - You have an error in your SQL


在我们开发的工程中,有时候会报
**[Err] 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


这种异常 不用多想,肯定是我们的sql语句出现问题,下面我只说我经常犯的一种错误。当然还有很多种错误,我们遇到再说。

这时候 我们不难发现 错误的原因是我们这里多了一个 ,号

有时候也会出现这种错误 [Err] 1054 - Unknown column ‘----------’ in 'field list’

这时候是我们的字段写错了 我们会发现数据库中并没有这个字段 而是我们的字段写错了

下面为大家写上两个同级sql

select a.Attribute_Id as Attribute_Id,          
       a.Attribute_Name as Attribute_Name,      
       a.Attribute_Alias as Attribute_Alias,
       a.Attribute_Unit as Attribute_Unit,
       a.DeviceType_Id as DeviceType_Id,
       a.SortCode as SortCode,
       a.UpdateTime as UpdateTime,   
       a.isdel as isDel
            from  zz_deviceattribute as a
where   Attribute_Id in(
select Attribute_Id from ZZ_DeviceAttributeRelation
where Device_Id =  '05871a37-a242-40f9-bbea-33bdea7009d5')



 select distinct 
                a.Attribute_Id as Attribute_Id,
                a.Attribute_Name as Attribute_Name,
                a.Attribute_Alias as Attribute_Alias,
                a.Attribute_Unit as Attribute_Unit,
                a.DeviceType_Id as DeviceType_Id,
                a.SortCode as SortCode,
                a.UpdateTime as UpdateTime,   
                a.isdel as isDel        
        from ZZ_DeviceAttributeRelation  as b
                inner join zz_deviceattribute as a 
                on a.Attribute_Id = b.Attribute_Id
                where b.Device_Id =  '05871a37-a242-40f9-bbea-33bdea7009d5'
                and a.isDel ='0'
                order by a.SortCode

sql语句 异常 Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your介绍到这里,更多sql学习请参考编程字典sql教程和问答部分,谢谢大家对编程字典的支持。


原文链接:https://blog.csdn.net/taiguolaotu/article/details/95171923?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163296314016780265486147%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=163296314016780265486147&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_v2~rank_v29-5-95171923.pc_v2_rank_blog_default&utm_term=sql&spm=1018.2226.3001.4450