Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Does any SQL have the idea of "ONLY"?

ONLY, as I understand it:

If , (for a given row, dimension, or group) has ONLY one distinct value of {Expression}, return it, else (more than one), return null.

I'm wondering if any flavor of SQL has the equivalent idea?

I think the answer is no, -- there is no direct , "out of the box" equivalent.

However, I think the same can be achieved manually, doing something like this. This is would-be SQL Server syntax -- but I don't know if the syntax is correct, I'm asking the idea in principle.... I'd be curious if any flavor of relational database supported this idea of "ONLY", but we use SQL Server.

SELECT

(CASE WHEN COUNT(DISTINCT Expression)>1 NULL() ELSE MAX(Expression) END) as OnlyExpression

GROUP BY {Dimension}

11 Replies
Not applicable
Author

It's theoretical question and I want a definite answer.

Specifically the business asked me to cross-check that the Qlikview chart (using an ONLY expression) -- which dipped drastically low in recent months -- was correctly calculating the numbers. (Of course it is... but when the business asks...)

I got the numbers in SQL Server to match the numbers in the Qlikview line chart using the SQL (Server?) expression I described in my original question, along with a Common Table Expression (CTE) -- which acted like my Qlikview "Load Script"

This is indeed the equivalent of ONLY:

(CASE WHEN COUNT(DISTINCT Expression)>1 THEN NULL ELSE MAX(Expression) END) as OnlyExpression

Not applicable
Author

Thank you... This is what I guessed and is indeed the same for SQL Server as Oracle Server