I am very new to the laravel subqueries , i am trying to fetch another table data but it’s showing an following error
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`)
query
DB::enableQueryLog();
$data = DB::table('bm_customercontactinfo')
->select(
DB::raw("SELECT tl_titlename FROM bm_titlelist WHERE tl_titleid=1")
)
->get();
dd(DB::getQueryLog());
can anyone help me where did i mistake ?
2
Answers
I think the issue is how you call the select method
You can check the documentation
https://laravel.com/docs/9.x/queries#select-statements
Though I’m not sure about your expected result, I assume that you are trying to get a specific title for each customer info result. You can use join for that case.
Please follow the documentation here. https://laravel.com/docs/9.x/queries#joins
You can use this