sql - Combine Columns with same ID and search the data -


i have table (tblabc) looks like

------------------------------- basicid   | filter1 | filter2 | -------------------------------  100          1         2  100          3         4  101          8         9 

what want on - want select basicid has filter1=1 , filter2=4. ie want output 100

can create view of combining basicid. looks similar

-------------------------------- basicid   | filter1|  filter2 | --------------------------------  100          1,3         2,4  101          8            9 

once done can search using simple search query
'select basicid tblnewlycreatedtable filter1=1 , filter2=4' , output 100.

to solve issue have tried following methods of have failed me not efficient because have around 12 filter filter on. not of filter applied time, @ times 4 filters, @ times 2 , @ time 12.

  1. select * tblabc
    , basicid in ( select basicid tblabc
    filter1 in (1) ) , basicid in ( select basicid tblabc
    filter2 in (4) )

2. using select finding results individually filter1 , filter2 using intersect intersect them.


1 more question have creating table filter fields varchar instead of int , searching on text good? advised many avoid this, cause efficiency problem. filtering on 12 varchar fields in same select query more efficient than, calling 12 select queries on int fields , combining them???

for mysql

select basicid,  group_concat(filter1 order filter1 asc separator ', ') filter1, group_concat(filter2 order filter2 asc separator ', ') filter2 tblabc group basicid 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -