Home » SQL & PL/SQL » SQL & PL/SQL » where we are using like this sql statemnet ----->>select 1 from table name
where we are using like this sql statemnet ----->>select 1 from table name [message #221720] Wed, 28 February 2007 03:17 Go to next message
victoryhendry
Messages: 95
Registered: January 2007
Location: Bangalore
Member

where we are using like this sql statemnet ----->>

1) select 1 from table name condition



2) select ename,eno from emp where 1>(some sub query)
Re: where we are using like this sql statemnet ----->>select 1 from table name [message #221722 is a reply to message #221720] Wed, 28 February 2007 03:29 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Please post these kind of general sql-questions in the newbie forum. These are not expert questions.

the "select 1 from table where.." construction is often used to verify the existence of (at least) a certain record. You only want to know if it is there or not, but you are not interested in the value of any column.
For example, you want to know if there is at least one John in your emp table, but you don't need his ID:
select 1 from emp where name = 'John';

The second construction speaks for itself if you would turn it around:
select * from table where (sub) < 1
Re: where we are using like this sql statemnet ----->>select 1 from table name [message #221724 is a reply to message #221720] Wed, 28 February 2007 03:30 Go to previous messageGo to next message
puneet.kakkar
Messages: 11
Registered: February 2007
Junior Member
1) select 1 from table name condition
This query is used where you want to handle a true/false type of condiiton.something like whether this will return a row or not.Generally used in subqueries. as in the below example.

select ename,eno from emp where exists
(select 1 from dept where
emp.eno = dept.eno)

will return only those employees having some department.



Re: where we are using like this sql statemnet ----->>select 1 from table name [message #221725 is a reply to message #221720] Wed, 28 February 2007 03:33 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Let's get this straight. You've posted some snippets of code from your system, with no context or idea what they're doing, and you want us to tell you why you're using them.

Excuse me while I fetch the Psychic Helmet (tm) from the workshop.

The first query might be used to check whether the conditions in the WHERE clause return one or more rows.
On the other hand, you might be looping through that query and summing the individual '1' values that it returns.

The second query is used to return all the rows from EMP where the value 1 is strictly greater than the value returned by the (presumably correlated) subquery.
Previous Topic: Write to a text file on remote server
Next Topic: Bypassing the index
Goto Forum:
  


Current Time: Sat Dec 10 01:28:11 CST 2016

Total time taken to generate the page: 0.08840 seconds