Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL join with empty data in one table
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00392660
Message ID:
00392684
Views:
9
>>I think that you need to try:
>>
>>SELECT * FROM sales Sa RIGHT JOIN...
>>
>>or INNER JOIN, depending on what you are trying to accomplish.
>
>Sorry, I forgot to mention what I want to get as result: The companies without corresponding records in the Sales table should get one record which the sales data is just empty. Because of the Where expression Sales.Price>0 this cannot be, because empty data is always null, so the sql cannot include this record in the cursor.
>I fear I cannot do this in one SQL line, and I have to do some tricks, unless someone comes up with a good idea!
>
>Thanks for help.

The simplest query would be SELECT yourfields FROM company LEFT JOIN sales ON ... WHERE price > 0 (just as you have it now) UNION SELECT yourfields FROM company WHERE company.id NOT IN (SELECT foreignkey FROM sales)

However, NOT IN is not Rushmore optimizable. It might go faster if you break it into two queries: do your LEFT JOIN and leave out the WHERE condition, INTO CURSOR cursor1. Then SELECT * FROM cursor1 WHERE price > 0 UNION SELECT * FROM cursor1 WHERE ISNULL(price) or something like that. ISNULL() is optimizable.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform