Showing posts with label fetch. Show all posts
Showing posts with label fetch. Show all posts

Friday, March 23, 2012

Query for tables.

how can i fetch somw rows having same field value?

my table is like:

name id

x 1

y 2

z 2

w 5

so how can i get rows y and z for id=id ?

This is a Transact-SQL question and should be asked over there... To save you some time though:

select name, id from [table] a, [table] b
where a.id = b.id and a.name <> b.name

Will return:

x 2
y 2|||

thx sir...

lemme modify for others...

select t1.* from table1 t1,table1 t2 where t1.id=t2.id and t1.name<>t2.name

Wednesday, March 21, 2012

query for a view

Hello,
I have a View called View1 with the field ID, F1, F2, F3. Now I need to check if (Total F1 < Total F2 + Total F3) per ID, if yes fetch all records (so if condition matches, I need to bring rows, not only totals) how can I write my view query to handle this?
Thanks,

SELECT *
FROM view1 v
WHERE id IN (SELECT id FROM view1 WHERE id = v.id AND SUM(f1) < SUM(f1)+SUM(f2) GROUP BY id)

Nick