Avatar of Roman F
Roman F
Flag for United States of America asked on

Please help me with the query

let say you run the query
Select * from tblMain

if you have the data you will get result:
num   name     zip
1      Steven 91356
2     Leonad 94875
and so on...
how about if you do not have anything you will get this
num   name     zip
how to modify the query and get just something like this:
0
Microsoft AccessSQL

Avatar of undefined
Last Comment
Sharath S

8/22/2022 - Mon
Armen Stein - Microsoft Access MVP since 2006

That's not how queries work.  They return records if they exist, not if they don't.  Can you tell us what you are trying to accomplish with this "zero" record?
Sharath S

Try this.
Select num,name,zip from tblMain
union all
select 0,null,null where not exists (select 1 from tblMain)

Open in new window

Roman F

ASKER
Thank you, guys.
To ArmenStein:i need to get the count of records even if there is no records. ---in this case is Zero is my result. I need the count to add to one more query results to get the final number
To: Sharath_123: i am getting the error message
Syntax error(missing operator) in query exression 'null where not exists (select 1 from tblMain)
'
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Sharath S

Check this
Select num,name,zip from tblMain
union 
select 0,null,null from tblMain where not exists (select 1 from tblMain)

Open in new window

Roman F

ASKER
thank you, it did not give me the error, but it does not give me the zero
i added the extra field Date
what i want, i think it make more sense, show me * from the table where date is not todays

and it stll gives me just a header:
num name zip Date

and i want like that
num name zip Date
0
is this possible???
Select num,name,zip,Date from tblMain where Date =format(now,"mm/dd/yyyy")
union 
select 0,null,null,null from tblMain where not exists (select 1 from tblMain)

Open in new window

ASKER CERTIFIED SOLUTION
Sharath S

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question