Home » SQL & PL/SQL » SQL & PL/SQL » select 1
select 1 [message #296316] Fri, 25 January 2008 13:53 Go to next message
oraclehelen
Messages: 2
Registered: January 2008
Junior Member
Hi,

I have a question about the SQL query, such as:
SELECT COUNT(a)
FROM tableA
WHERE a IS NOT NULL
AND EXISTS (SELECT 1 FROM tableB ...);

I would like to know what the "SELECT 1" means, is it equal to "SELECT *"?

Thanks for any replies.

Helen
Re: select 1 [message #296318 is a reply to message #296316] Fri, 25 January 2008 14:02 Go to previous messageGo to next message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
It is equal to "SELECT anything"; the purpose of EXISTS isn't to, actually, fetch something (useful), but to show whether there is at least one record that satisfies the condition.

Some people use "SELECT 1"; the others will write it as "SELECT NULL". It really doesn't matter.
Re: select 1 [message #296320 is a reply to message #296316] Fri, 25 January 2008 14:09 Go to previous messageGo to next message
Michel Cadot
Messages: 64153
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
In addition to LittleFoot's answer, as it is meaningless, use "select null" just to clearly show that the expression is meaningless.

Regards
Michel
Re: select 1 [message #296322 is a reply to message #296320] Fri, 25 January 2008 14:11 Go to previous messageGo to next message
oraclehelen
Messages: 2
Registered: January 2008
Junior Member
Hi there,

Thanks so much for your replies.

Re: select 1 [message #296441 is a reply to message #296322] Sun, 27 January 2008 07:50 Go to previous messageGo to next message
KrishnaBoppana
Messages: 12
Registered: March 2007
Location: Boston, MA
Junior Member
It is just a little trick in SQL to satisfy the Select clause that requires some column to be specified. When used in conjunction with exists, your main goal is to get the results from the exists clause.

-Krishna

[Updated on: Sun, 27 January 2008 09:12] by Moderator

Report message to a moderator

Re: select 1 [message #296447 is a reply to message #296441] Sun, 27 January 2008 09:12 Go to previous message
Michel Cadot
Messages: 64153
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
This a trick for what?
This post is once again meaningless.
Are you an expert in non-sense?

Regards
Michel
Previous Topic: dataware house query help !
Next Topic: Find the nth record from a table
Goto Forum:
  


Current Time: Sun Dec 11 06:36:37 CST 2016

Total time taken to generate the page: 0.09248 seconds