I have a table Calculators and I want to create an SQL query that returns a boolean result, true if and only if Calculators is not empty so I can return this boolean to my application and order more.
The natural thing would be to use
EXISTS Calculators
But for my assignment, I’m not allowed to use either the EXISTS keyword or the COUNT keyword (or any other cardinality operators) in any of my queries.
My best attempt at a query to perform this so far is
((SELECT * FROM Calculators) IN ANY (SELECT * FROM Calculators))
But this just gives a syntax error that I can’t figure out.
I had another attempt:
((SELECT * FROM Calculators) IN Calculators)
But this also gives a syntax error? I really think this can be done using IN somehow, but I can’t quite form the query. Can you help me get a boolean from my query that returns true if Calculators is non-empty?
Thank you!
I’m confused by your question. You want to return a boolean result if your table is not empty? If so, something like this should work:
Sample SQL Fiddle
This will return a single boolean True value if any records exist. It won’t return anything if no records exist. Don’t think you can return false without using
COUNTor some other aggregate. Might depend on your RDBMS.–EDIT–
Seeing that you’re using Oracle, here is a hack to return true or false:
And more fiddle.