i have a table of data like this with four columns(id1,id2,keyname,keyvalue)
id1 id2 keyname keyvalue
1 -- 111 -- a -- 2
2 -- 111 -- b -- 3
3 -- 222 -- a -- 2
4 -- 222 -- b -- 4
how can i get the id2 value = 111
i written this query
select id2 from table where (a=2) and (b=3)
but it giving empty result.
can any one suggest me the better solution ?
when i placed (or) in between the conditions it giving result but i need to satisfy both conditions
select data from a table and it satisfy two conditions
Moderator: General Moderators
Re: select data from a table and it satisfy two conditions
That would do it, but then if you had any other rows that had 111 in it then you would never get the proper results. From looking at your table set upselect id2 from table where (a=2) and (b=3)
Code: Select all
id1 id2 keyname keyvalue
1 -- 111 -- a -- 2
2 -- 111 -- b -- 3
3 -- 222 -- a -- 2
4 -- 222 -- b -- 4
/* this would return all rows that had that value */
select * from table where id2 = 111
Re: select data from a table and it satisfy two conditions
yes, i have other rows with id2 as 111 like
id1 id2 keyname keyvalue
1 -- 111 -- a -- 2
2 -- 111 -- b -- 3
3 -- 222 -- a -- 2
4 -- 222 -- b -- 4
5 -- 111-- d -- 6
Here i have to get id2 value which is 111 ,with the given conditions of (a=2) and (b=3)
how can i write the query ?
Thanks,
NMreddy
id1 id2 keyname keyvalue
1 -- 111 -- a -- 2
2 -- 111 -- b -- 3
3 -- 222 -- a -- 2
4 -- 222 -- b -- 4
5 -- 111-- d -- 6
Here i have to get id2 value which is 111 ,with the given conditions of (a=2) and (b=3)
how can i write the query ?
Thanks,
NMreddy
Re: select data from a table and it satisfy two conditions
Code: Select all
select * from tbl where id2 =111 AND ((keyname ='a' and keyvalue='2') OR (keyname='b' and keyvalue='3'));
Re: select data from a table and it satisfy two conditions
here i have to get id2 value and it satisfy both conditions ((keyname ='a' and keyvalue='2') AND (keyname='b' and keyvalue='3'))