I have two tables in a database table1
and table2
First of all I have used the INNER JOIN
to obtain values from table1 and table2.
SELECT table1.id, table1.name, table2.location, table2.address FROM table1 INNER JOIN table2 ON table1.id=table2.id;
This query works just fine but the thing is that the address column in table2 table2.address
contains empty/no values. Which I don’t want to fetch. How to customize this query?
Furthermore,
I also want to filter a specific location table2.location
.
For example, in simple words I want that when the results are fetched the location has to be “London” and addresses that are non-empty
.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
SELECT table1.id, table1.name,
table2.location, table2.address
FROM table1
INNER JOIN table2 ON table1.id=table2.id
WHERE table2.address IS NOT NULL
AND table2.location = 'London'
;
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0