【问题标题】:SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; Laravel [closed]SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误; Laravel [关闭]
【发布时间】:2019-08-28 07:04:01
【问题描述】:

所以,我尝试在查询中添加新行,但不幸的是我遇到了这个错误:

SQLSTATE[42000]:语法错误或访问冲突:1064 你有一个 SQL 语法错误;检查与您对应的手册 MariaDB 服务器版本,用于在 'FROM 附近使用正确的语法 职业解决方案

我做了什么来补充:

career_solutions_certification as certification,

INNER JOIN certification
ON career_solutions_certification.id = career_solutions.certification

 $career_solution->topic_certification_id = $request['topic_certification_id'];$career_solution->save();

这是我的代码

$career_solutions_data = DB::select(" 
SELECT 
career_solutions.id,
career_solutions.user_id,  
career_solutions.subject, 
career_solutions.date, 
career_solutions.public, 
career_solutions.views, 
career_solutions.optional, 
career_solutions.on_offer, 
users.username, 
users.profile_picture, 
categories.category, 
categories.category_url, 
categories.color, 
career_solutions_categories.category as sub_category,
career_solutions_format.category as event_format,
career_solutions_certification.category as certification,

FROM career_solutions 

INNER JOIN categories 
ON categories.id = career_solutions.topic_category_id 

INNER JOIN career_solutions_format
ON career_solutions_format.id = career_solutions.topic_format_id

INNER JOIN certification
ON career_solutions_certification.id = career_solutions.certification

INNER JOIN career_solutions_categories 
ON career_solutions_categories.id = career_solutions.topic_subcategory_id 

INNER JOIN users 
ON users.id = career_solutions.user_id 


INNER JOIN privacy_settings 
ON privacy_settings.user_id = users.id 

WHERE users.deleted_at IS NULL 
AND ( 
(privacy_settings.career_solutions = 0 AND public = 1 ) 
OR (users.id IN ( 

SELECT contacts.contact_id 
FROM contacts 
WHERE contacts.user_id = $id 
) 
) 
) 

OR users.id = $id 

ORDER BY date desc limit 5000 
"); 

我的表是career_solutions_certification/ 列idcategory

【问题讨论】:

  • career_solutions_certification.category as certification,中多了一个逗号

标签: php database laravel


【解决方案1】:
career_solutions_certification.category as certification

可能没有 - ,

【讨论】:

  • 谢谢 :) 所以最后一个每次都应该不用逗号?
  • 是的。查询的最后一列中的逗号不正确
【解决方案2】:

选择列后有额外的逗号

Wrong : career_solutions_certification.category as certification**,**



Correct : career_solutions_certification.category as certification

【讨论】:

    猜你喜欢
    • 2021-09-15
    • 1970-01-01
    • 2020-05-03
    • 2020-02-15
    • 1970-01-01
    • 1970-01-01
    • 2020-03-02
    • 2019-08-08
    相关资源
    最近更新 更多