What is wrong with my query?
-
Greetings experts, when I run the following query, it correctly gives me all the records from tableA but all NULL values from tableB even though there are records in tableB. Any ideas what I am doing wrong?
SELECT DISTINCT isnull(a.district\_combo,'Not available'), a.voter\_fname, a.voter\_mname, a.voter\_lname, a.voter\_suffix, COALESCE(a.str\_number,'')+' '+COALESCE(a.str\_name,'')+' '+COALESCE(a.str\_suffix,'')+' '+COALESCE(a.str\_apt,'') AS res\_addr, a.str\_city, a.state, a.str\_zip, COALESCE(a.mail\_str\_num,'')+' '+COALESCE(a.mail\_str\_name,'')+' '+COALESCE(a.mail\_srt\_suff,'')+' '+COALESCE(a.mail\_apt,'')+' '+COALESCE(a.mail\_city,'')+' '+COALESCE(a.mail\_state,'')+' '+COALESCE(a.mail\_zip,'') AS mail\_address, a.dob, b.\* FROM dbo.tableA a LEFT OUTER JOIN dbo.tableB b ON a.record\_id=b.record\_id
-
Greetings experts, when I run the following query, it correctly gives me all the records from tableA but all NULL values from tableB even though there are records in tableB. Any ideas what I am doing wrong?
SELECT DISTINCT isnull(a.district\_combo,'Not available'), a.voter\_fname, a.voter\_mname, a.voter\_lname, a.voter\_suffix, COALESCE(a.str\_number,'')+' '+COALESCE(a.str\_name,'')+' '+COALESCE(a.str\_suffix,'')+' '+COALESCE(a.str\_apt,'') AS res\_addr, a.str\_city, a.state, a.str\_zip, COALESCE(a.mail\_str\_num,'')+' '+COALESCE(a.mail\_str\_name,'')+' '+COALESCE(a.mail\_srt\_suff,'')+' '+COALESCE(a.mail\_apt,'')+' '+COALESCE(a.mail\_city,'')+' '+COALESCE(a.mail\_state,'')+' '+COALESCE(a.mail\_zip,'') AS mail\_address, a.dob, b.\* FROM dbo.tableA a LEFT OUTER JOIN dbo.tableB b ON a.record\_id=b.record\_id
If it's giving you null values from tableB, then there aren't any records in tableB which match a record in tableA using the join condition you've supplied.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Greetings experts, when I run the following query, it correctly gives me all the records from tableA but all NULL values from tableB even though there are records in tableB. Any ideas what I am doing wrong?
SELECT DISTINCT isnull(a.district\_combo,'Not available'), a.voter\_fname, a.voter\_mname, a.voter\_lname, a.voter\_suffix, COALESCE(a.str\_number,'')+' '+COALESCE(a.str\_name,'')+' '+COALESCE(a.str\_suffix,'')+' '+COALESCE(a.str\_apt,'') AS res\_addr, a.str\_city, a.state, a.str\_zip, COALESCE(a.mail\_str\_num,'')+' '+COALESCE(a.mail\_str\_name,'')+' '+COALESCE(a.mail\_srt\_suff,'')+' '+COALESCE(a.mail\_apt,'')+' '+COALESCE(a.mail\_city,'')+' '+COALESCE(a.mail\_state,'')+' '+COALESCE(a.mail\_zip,'') AS mail\_address, a.dob, b.\* FROM dbo.tableA a LEFT OUTER JOIN dbo.tableB b ON a.record\_id=b.record\_id