So.I have what is, for me anyway, a fairly complex SQL select statement over
a set of MySQL tables which uses RIGHT and LEFT JOINS to search about 18
tables.
The Select works in general.except for one thing. I'm getting NULL records
and I don't want them. J
In the MySQL tables, I have created a common key that exists in all of the
tables named CaseID.
I am using a RIGHT and LEFT JOIN to get the data from these files.
Some of the tables in my JOIN(s) do not have records in them that match the
selection criteria while others do have matching data.
If I run my SQL statement outside of PHP, say within the MySQL Admin page
(if you're using WAMP for example).the records are returned, but I see the
null records from the tables that do not have any records in them that match
the selection criteria.
When I run this same SELECT in PHP, and I try to access the value of the
common field CaseID, I'm getting a null in that field value because I'm
getting the last record the SELECT returned, which is a NULL record because
there wasn't any matching record in that particular table so that common
field name is blank/null.
What I really want to do is to be able to run my SQL statement and NOT
return NULL (empty) records.
That is.if I have 3 tables, and the first table and the third table each
have a record that matches my selection criteria, but the second table does
not, I only want to return the data from the first and the last table.
I know I could give unique names to the field CaseID (and any other fields
that are the same in multiple tables) but I'm hoping to not have to do that
since I'd have to make changes in a lot of places to implement that
solution. I'd rather just avoid returning NULL records if I can.
I have included the actual SQL statement here, in its entirety, but probably
if you know how to do what I'm looking to do, you don't need to see my SQL
anyway. However, having it here will help someone else later on when they
search the archives for a similar solution.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.