WHERE clause in an SQL query
<p>I THINK what is happening with this query is if there are no records in the GenericAttribute table associated with the Product, then that product is not displayed. See line below in WHERE clause: "AND GenericAttribute.KeyGroup = 'Product'"</p>

<p>Is there a way to reword so that that part of the WHERE is ignored if no associated record in the GenericAttribute table?</p>

<p>Also, looking at my ORDER BY clause, will a record from the product table still show up if it has no associated record in the Pvl_AdDates table?</p>

<p>Thanks!</p>

<pre><code>SELECT DISTINCT Product_Category_Mapping.CategoryId, Product.Id, Product.Name, Product.ShortDescription, Pvl_AdDates.Caption, Pvl_AdDates.EventDateTime, convert(varchar(25), Pvl_AdDates.EventDateTime, 120) AS TheDate, Pvl_AdDates.DisplayOrder, Pvl_Urls.URL, [Address].FirstName, [Address].LastName, [Address].Email, [Address].Company, [Address].City, [Address].Address1, [Address].Address2, [Address].ZipPostalCode, [Address].PhoneNumber 
FROM [Address] 
RIGHT JOIN (GenericAttribute  
RIGHT JOIN (Pvl_Urls RIGHT JOIN (Pvl_AdDates 
RIGHT JOIN (Product_Category_Mapping 
LEFT JOIN Product 
ON Product_Category_Mapping.ProductId = Product.Id) 
ON Pvl_AdDates.ProductId = Product.Id) 
ON Pvl_Urls.ProductId = Product.Id) 
ON GenericAttribute.EntityId = Product.Id) 
ON Address.Id = convert(int, GenericAttribute.Value) 
WHERE 
Product_Category_Mapping.CategoryId=12 
AND GenericAttribute.KeyGroup = 'Product'
AND Product.Published=1 
AND Product.Deleted=0 
AND Product.AvailableStartDateTimeUtc &lt;= getdate() 
AND Product.AvailableEndDateTimeUtc &gt;= getdate() 
ORDER BY 
Pvl_AdDates.EventDateTime DESC, 
Product.Id, 
Pvl_AdDates.DisplayOrder
</code></pre>