Click here to Skip to main content
15,885,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
Table1
----------

name          age       address          city       state  
------------------------------------------------------------
ram           10        asdf             asdfrg      tn
kumar         20        fyudfy          adfgdfgfd    ap
raj           15        asfgafg          asfgfg      up
sai           25        asdfgaf        asfgasfg      ka
dachu         23        afgfagg        fdgfgfgg      jk


I want the output is =
C#
age
----
15



without where condition to find


eg:

column(age,raj)
this type of any function is there in SQL or ACCESS or MYSQL.

Pls help...
Posted

It would have helped if you had described what that value represents in terms of this data but your reference to
sic:
this type of any function is there in SQL or ACCESS or MYSQL
leads me to think of mathematical functions[^]

Of the data shown
Average = 18
Median = 20 
There is no mode

However the range is 15 so this query will get the results you want:
select max(age) - min(age) as ageRange from Table1


[EDIT]
My somewhat sarcastic solution above didn't go down so well. However, despite what other members are saying it is possible to filter the table without using WHERE. The real point is that you really shouldn't do it this way! (And I really do mean really).
It can be achieved using a CURSOR[^] and an IF[^] statement. For example:
SQL
declare @AgeToCheck int = 15
declare @ResultFound int = 0

declare @name varchar(125)
declare @age int
declare @address varchar(125)
declare @city varchar(125)
declare @state varchar(125)

DECLARE @ACursor CURSOR 
SET @ACursor = CURSOR FOR
	SELECT [name], age,[address], city,[state]
	FROM Table1

OPEN @ACursor
FETCH NEXT FROM @ACursor INTO @name, @age, @address, @city, @state
WHILE @@FETCH_STATUS = 0
BEGIN

	IF @age = @AgeToCheck
	BEGIN
		SET @ResultFound = 1
		BREAK
	END
	FETCH NEXT FROM @ACursor INTO @name, @age, @address, @city, @state
END
CLOSE @ACursor
DEALLOCATE @ACursor
select @name,@age,@address,@city,@state

Now doesn't that look horrible compared to
SQL
SELECT [name], age,[address], city,[state]
	FROM Table1
	WHERE age = @AgeToCheck

I cannot stress strongly enough that, just because something is possible does not mean that it is a sensible solution. Do not filter tables using Cursors.
 
Share this answer
 
v2
Comments
Naveen.Sanagasetti 22-Dec-15 4:19am    
Hi Chill, I won't agree with your answer if he needs kumar age then you made one more query for kumar?
CHill60 22-Dec-15 5:34am    
As I stated in my solution the OP hasn't actually described what they want. As it is, this query will give the output the OP said they wanted. I was being somewhat facetious
Mehdi Gholam 22-Dec-15 5:58am    
5'ed for a creative solution :)
CHill60 22-Dec-15 6:00am    
Thank you. Creative - may be, Advisable - oh no! Just no! :-)
You can't filter a table without a WHERE condition.

Try to learn some fundamentals, first.
 
Share this answer
 
Comments
Naveen.Sanagasetti 22-Dec-15 4:19am    
I totally agree with you Mehdi, without where conditions that's not possible to give consistent output in all cases.
CHill60 22-Dec-15 5:55am    
Not quite true - see my amended solution. It's not a good way to go about it but it is possible. BTW I have only done the equivalent of select top 1 not all matches in my trivial example

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900