However, this DB::table('othertable')->select('id')->whereRaw('mytbl.aaa = bbb')->first() will return a stdClass instance, so you probably want value('id') rather than select('id')->first():
tried to change it to value('id') but still got the same error, it seems not recognizing the alias from mytable since it's outside of the second DB::table... I guess.
because that column belongs to the first table, without alias still got the same error (Unknown column) which is correct since the second table doesn't have that column.
Anyway, I want to use DB::raw for the second sql, but the problem is I need to specify the database name of the table in the real case like this: