Skip to content
Advertisement

Using the OR operator in a nested SQL Statement

I have a database with vendors, what they sell and where they are located.

I need to search for vendors that are based off of a specific locality like a state or for vendors who sell a certain number of products.

An example of this question is:

What are the full names of all vendors who can supply more than one item or are based in Illinois?

This would be easy if I could use two sql queries (but for this problem I cannot).

Assuming there is no joins between tables used, my solution is incorrect but this is what I tried

ERROR at line 1: ORA-00933: SQL command not properly ended

If I try each one separately, I get these results

Using Illonois

VENDOR_ID NAME COUNT(CS.PRODUCT_ID)


Using the number of products

VENDOR_ID NAME COUNT(CS.PRODUCT_ID)


26 rows selected.

Basically I want to merge these two queries into one. Is there a way to nest these together?

Advertisement

Answer

I would be inclined to do:

Note: this isn’t perfect, because a vendor can have multiple addresses. So, I think the better solution is:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement