我对laravel子查询非常陌生,我尝试获取另一个表数据,但它显示以下错误
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT tl_titlename FROM bm_titlelist WHERE tl_titleid=1 from `bm_customercon...' at line 1 (SQL: select SELECT tl_titlename FROM bm_titlelist WHERE tl_titleid=1 from `bm_customercontactinfo`)
查询
DB::enableQueryLog();
$data = DB::table('bm_customercontactinfo')
->select(
DB::raw("SELECT tl_titlename FROM bm_titlelist WHERE tl_titleid=1")
)
->get();
dd(DB::getQueryLog());
谁能帮我一下我错在哪里了?
1条答案
按热度按时间lp0sw83n1#
我认为问题在于如何调用select方法
您可以查看文档https://laravel.com/docs/9.x/queries#select-statements
虽然我不确定您的预期结果,但我假设您正在尝试为每个客户信息结果获取特定标题。在这种情况下,您可以使用join。请按照此处的文档进行操作。https://laravel.com/docs/9.x/queries#joins