Link to home
Start Free TrialLog in
Avatar of gvamsimba
gvamsimbaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

TSQL Query


HI, Below is my sample data from a table. I just want
to get those id's where the answer to qid 82 is greater
than the answer given to qid 1306.

   Can any one give me that TSQL script please ?

Thanks



id QID     Answer Startdate
         
 1  1306    2018   31/03/2009
 1  82      3099   30/09/2007
Avatar of Sara bhai
Sara bhai
Flag of India image

SELECT id  FROM TABLE
WHERE id > 82  AND id = 1306

select A.*
from Table1 A
inner join  table1 B on B.ID = A.ID
where A.QID = 82
and B.QID = 1306
and A.Answer > B.Answer
SELECT id  FROM TABLE
WHERE qid > 82  AND qid = 1306
Hi,
Please try following:

select a.id,  a.QID, a.Answer, a.Startdate
From Table a
      Inner Join Table on a.Answer>b.Answer  
Where a.Answer = 82

Thanks
I don't think your statement of the problem makes sense.....and as a result, I don't think the solutions do either.

arabhai : will always return the id from qid = 1306
ewangoya: will always return the row with qid = 83 unless the values for answer are changed in which case it may return nothing - these are the only two possibilities

Can I respectfully suggest you check your statement of the requirements?
ASKER CERTIFIED SOLUTION
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial