So I have Laravel 5.2 and in my SQL database I have several tables:
books
with fields title
, author
and year
,
journals
with fields title
, year
and price
newspapers
with fields title
, town
, year
I need to get a list of all titles from all three tables, where the year is 1994. I've tried to do the following
$titles = DB::table('books')->where('books.year', 1994)->leftjoin('journals as journals', 'books.year', '=', 'journals.year')->leftjoin('newspapers as newspapers', 'books.year', '=', 'newspapers.year')->select('books.title', 'journals.title', 'newspapers.title')->get();
But with this query I get entries full of null
s, and only newspapers are filled in. What am I doing wrong?