database - Sql correct syntax for raw query in laravel -


i have tested query in mysql , works. doesn't work in mine controller. can correct please?

 $albi = db::table(db::raw("(select                           albi.id,                           albi.coveralbo,                           albi.nazione,                           albi.editore,                           albi.nomecollanaufficiale,                           albi.annopubblicazione                           albi left join albi_user au on a.id = au.albi_id                           , au.user_id = $user_id                           au.albi_id null)")); 

this error:

sqlstate[42000]: syntax error or access violation: 1248 every derived table must have own alias

please me!!!

this because you're using db::table() , placing raw query inside (creating sub query) , not giving alias.

to above code work should need change last line like:

where au.albi_id null) t1")); //notice "t1" alias 

or db::select():

$albi = db::select("select                       a.id,                       a.coveralbo,                       a.nazione,                       a.editore,                       a.nomecollanaufficiale,                       a.annopubblicazione                       albi left join albi_user au on a.id = au.albi_id                       , au.user_id = $user_id                       au.albi_id null"); 

please note not same select() db::table()->select()


or use the query builder:

$albi = db::table('albi')     ->select('id', 'coveralbo', 'nazione', 'editore', 'nomecollanaufficiale', 'annopubblicazione')     ->leftjoin('albi_user', 'albi.id', 'albi_user.alibi_id')     ->where('albi_user.user_id', $user_id)     ->wherenull('albi_user.albi_id')     ->get(); 

hope helps!


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -