Mysql searching with commaseparated POST

Go To StackoverFlow.com

-2

Im doing a search where the POST is: sok3 = 0,2,6

I would then like to select all users that matches this POST(sok3) from table2, where columns could be like this:

table1:

id|name
1 |myname

table2:

id|uid|sok3
0 |1  |0
1 |1  |2
2 |1  |4
3 |1  |6
4 |6  |1
5 |6  |2
6 |6  |4

I have tried with:

SELECT * from table1 as tab1 LEFT JOIN table2 as tab2 ON(tab2.uid = tab1.id) Where .. 

The result i get is 3 matches. BUT i only want 1 result, where there is a match. if 0 then its a match, if 0,2 there is match etc..

I know i dont even search for the Post.. just dont know how to solve it :/

How can i solve this one? :)

2012-04-05 18:08
by teecee


1

Either use SELECT DISTINCT name or GROUP BY name in your query

2012-04-05 18:20
by Aerik
Thanks! That solves having 3 results, but the search critera is not searched for - teecee 2012-04-05 18:25
How about "SELECT DISTINCT tab1.name from table1 as tab1 LEFT JOIN table2 as tab2 ON(tab2.uid = tab1.id) Where tab2.sok3 IN (".mysqlrealescapestring($POST['sok3']).") - Aerik 2012-04-05 18:30
Thank you so much! = - teecee 2012-04-05 20:15
Ads