Jump to content

Multiple search


sridhar golyandla

Recommended Posts

It depends...

Do you want the result to match the search string entered exactly?

Or does the search string have to be somewhere in the result?

This would return all results where $search is somewhere in coln

SELECT * FROM table WHERE coln LIKE '%$search%'

 

Make sure to escape $search properly before putting it into a query

Link to comment
Share on other sites

i tried with that link a long back ago... but it was not working properly with my application....

 

How to search the value whether it has in col1, col2...... to con n

 

SELECT DISTINCT r.rid, r.email, s.col1, s.col2, s.col3, s.col4, s.col5

FROM register r, skill s

WHERE s.col1 LIKE '%PHP%'

OR s.col2 LIKE '%PHP%'

OR s.col3 LIKE '%PHP%'

OR s.col4 LIKE '%PHP%'

OR s.col5 LIKE '%PHP%'

AND s.rid= r.rid;

 

getting duplicate values. please help me out.

Link to comment
Share on other sites

 

try grouping them.

 

 

 

SELECT DISTINCT r.rid, r.email, s.col1, s.col2, s.col3, s.col4, s.col5

FROM register r, skill s

WHERE (s.col1 LIKE '%PHP%')

OR (s.col2 LIKE '%PHP%')

OR (s.col3 LIKE '%PHP%')

OR (s.col4 LIKE '%PHP%')

OR (s.col5 LIKE '%PHP%')

AND s.rid= r.rid;

Link to comment
Share on other sites

Hi

 

Seen an error:-

 

SELECT DISTINCT r.rid, r.email, s.col1, s.col2, s.col3, s.col4, s.col5

FROM register r, skill s

WHERE (s.col1 LIKE '%PHP%'

OR s.col2 LIKE '%PHP%'

OR s.col3 LIKE '%PHP%'

OR s.col4 LIKE '%PHP%'

OR s.col5 LIKE '%PHP%')

AND s.rid= r.rid;

 

How you had the SQL the last like statement would be ANDed with the s.rid = r.rid, which would mess up the table join.

 

Probably better would be:-

 

SELECT DISTINCT r.rid, r.email, s.col1, s.col2, s.col3, s.col4, s.col5

FROM register r JOIN skill s ON s.rid= r.rid

WHERE s.col1 LIKE '%PHP%'

OR s.col2 LIKE '%PHP%'

OR s.col3 LIKE '%PHP%'

OR s.col4 LIKE '%PHP%'

OR s.col5 LIKE '%PHP%';

 

All the best

 

Keith

Link to comment
Share on other sites

SELECT DISTINCT r.rid, r.email, s.col1, s.col2, s.col3, s.col4, s.col5, q.col1, j.col1,

 

c.col1

FROM register r JOIN skill s ON s.rid= r.rid join qal q on q.rid=r.rid join job j on j.rid=r.rid join col c on c.rid=r.rid

WHERE s.col1 LIKE '%PHP%'

OR s.col2 LIKE '%PHP%'

OR s.col3 LIKE '%PHP%'

OR s.col4 LIKE '%PHP%'

OR s.col5 LIKE '%PHP%';

Link to comment
Share on other sites

Hi

 

That looks like it should work. However I would suspect the issue might be that rid is not unique on one of those tables, hence bringing back rows that duplicated (eg, say table job had 2 rows for an rid of 1, yet these rows had the same value of coll but possibly a different value of another column you would get a full duplicate row).

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.