Click to See Complete Forum and Search --> : [RESOLVED] Easy SELECT question


dz_boy
08-18-2007, 02:47 PM
I've been using the following SQL query in conjunction with PHP. It works right now, but only when every single field it uses is filled out. Is there a way to modify this query to allow for null values and not to exclude records because of one null field?

SELECT c . item_id , c . cost , c . quantity , c . acquired , c . item_name , c . description , d . location_name , d . location_link FROM `Customer` a , `List_Xref` b , `Item` c , `Location` d WHERE a . customer_id = '. $_COOKIE['user_id'] .' and a . list_id = b . list_id and b . item_id = c . item_id and c . location_id = d . location_id

For example, the location_name or location_link fields are optional for my users. Is there a way to retrieve the rest of the selected information for every record that fits all the other criteria, and then add the location info if it is applicable? I don't think I'm explaining this well... I'm very new at this. Any help or insight is appreciated!

NogDog
08-19-2007, 07:58 AM
Yikes! How about some line-breaks in that puppy so we can read it. :)

dz_boy
08-19-2007, 10:24 AM
Oops... I didn't realize it hadn't wrapped the words. Sorry! Hope this helps.

SELECT c . item_id , c . cost , c . quantity , c . acquired ,
c . item_name , c . description , d . location_name , d . location_link
FROM `Customer` a , `List_Xref` b , `Item` c , `Location` d
WHERE a . customer_id = '. $_COOKIE['user_id'] .'
and a . list_id = b . list_id
and b . item_id = c . item_id
and c . location_id = d . location_id