Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Please help me with the query

Posted on 2011-03-09
6
Medium Priority
?
277 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:rfedorov
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9
ID: 35089458
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?
0
 
LVL 41

Expert Comment

by:Sharath
ID: 35089494
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

0
 

Author Comment

by:rfedorov
ID: 35095788
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)
'
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 41

Expert Comment

by:Sharath
ID: 35102035
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

0
 

Author Comment

by:rfedorov
ID: 35109940
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

0
 
LVL 41

Accepted Solution

by:
Sharath earned 2000 total points
ID: 35113342
You have to add the WHERE condition in the sub query also.
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 where Date =format(now,"mm/dd/yyyy"))

Open in new window

0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question