My data has orderid, userid and userage along with a lot other data.
Now age is something that the user can provide if and whenever he/she wishes.
orderid userid userage
4 1 18
5 3 25
Select orderid from table where userage=18
You haven't disclosed how you represent missing data. Many DBMS designs use NULL values for that. If that's your situation
SELECT orderid FROM table WHERE (userage = 18 OR userage IS NULL)
If you use -1 for missing data (you probably don't, but I'm trying to make a point here)
SELECT orderid FROM table WHERE (userage = 18 OR userage = -1)
Notice that when a column value is NULL, no test for equality or inequality ever comes back try. You must is
IS NULL or
IS NOT NULL to test NULLs.
In Oracle, zero length text strings are NULL. That's not so in other DBMSs.
If you're looking for all orders from a user who has ever given an age of 18, this will do the trick
SELECT orderid FROM table WHERE userid IN (SELECT userid FROM table where userage = 18)