I have a table like this
Table
userid
fieldid
fieldvalue
where userid and fieldid are the primary key pair for this table.
I want to create a sql query that will find all users with fieldvalueequal to something for the selectedfieldid
For example, for values
fieldid: 817
fieldvalue: 'yes'
I may have a sql query, for example:
select userid FROM table where (fieldid=817 AND fieldvalue='yes')
This request is working fine.
However, if I have a second or third criterion by making a request for example:
select userid
FROM table
where (fieldid=817 AND fieldvalue='yes')
AND (fieldid=818 AND fieldvalue='no')
returns an empty result, but the conditions are met in an individual criterion.
Is there any way to fix this?
Update
I forgot to record a precedent (sentences)
userid, fieldid, fieldvalue
1 , 817, yes
1, 818, no
1, 825, yes
2, 817, yes
2, 818, yes
3, 829, no
for this table, I need a sql query that finds users who meet the following conditions: field value 817 is yes and fieldid 818 is no
OR, fieldid 817, yes, fieldid 818, no
, .
userid
1
userid
1
2
userid 2 . .