exists and using x

when we use exists in a query

what is meaning of select x means

select count(order_nr) from xyz where ord_cd="10"
exists(

select 'x' from ABC a where ef=ge
and
a.some_cd='zz'
and
((datediff(...)or (datediff.....))


i checked below link
https://www.geeksforgeeks.org/sql-exists/

how to validate my results are correct or not

how to break above query to see if difference of time is actually correct?
please advise
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornSQL Server Data DudeCommented:
>what is meaning of select x means
<Wild guess>  The 'x' doesn't really matter, as the subquery will either return rows or not, and the main query will return rows or not based on whether the subquery returns rows or not.  So it could really read SELECT 1, SELECT SomeColumnName ... doesn't matter.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
With some RDBMS, in the early days 10 years ago or so, it has been important to properly choose what has been selected in an "exists" clause - because it had performance penalities. So folks got into the habit to use constants like 1 or 'X'. Some RDBMS required to use "*" to select all columns for good performance.
Nowadays, it doesn't matter, and many users consider it confusing to put in something different than a simple * or 1 here.
PortletPaulEE Topic AdvisorCommented:
When using EXISTS the correlated subquery does not actually need to return data, in effect it is only the from & where clauses that do the work. The select clause is there because syntax rules dictate it must be used. Often "select *" or "select 1" or "select NULL" is used but 'x'  is also valid because  it really doesn't matter what this clause contains.

SELECT
    COUNT( order_nr )
FROM xyz
WHERE ord_cd = '10'
AND EXISTS (
    SELECT  'x'   << this clause is ignored, common options are:   *  1  NULL,
   FROM ABC a
    WHERE XYZ.colx = a.coly  -- all the needed work done here

)

Using EXISTS forms a "left semi-join"  and has been part of SQL since its inception by  Chamberlin & Boyce in the early 1970's.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.