Gruzin Posted February 11, 2007 Share Posted February 11, 2007 Hi everyone, I'am having some trouble with mysql select... say I have a field DrugID (INT) and there are some records in it (2, 6, 12, 12). if there are two or more same records, like 12 three times, how can I detect that? hope you understand me, if not please let me know... Thanks, George Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 11, 2007 Share Posted February 11, 2007 $query = mysql_query("SELECT * FROM `table` WHERE DrugID='12'"); $query2 = mysql_num_rows($query); //counts how many ids = 12 Quote Link to comment Share on other sites More sharing options...
Gruzin Posted February 11, 2007 Author Share Posted February 11, 2007 Thanks but, I don'r really know exact number, I mean: $query = mysql_query("SELECT * FROM `table` WHERE DrugID='$var'"); Thanks, George Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 So what's the problem? Quote Link to comment Share on other sites More sharing options...
Gruzin Posted February 11, 2007 Author Share Posted February 11, 2007 OK, here is my test script: $apt = mysql_query("SELECT DrugRemainder.MatID,Drugstores.DrugID FROM DrugRemainder,Drugstores WHERE (DrugRemainder.MatID='$id' AND Drugstores.DrugID=DrugRemainder.DrugID)"); and I don't want to show same results, I mean if there is a record 12 three times I want to count it as one. Thanks, George Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 Use the MYSQL DISTINCT keyword. http://dev.mysql.com/doc/refman/5.0/en/select.html Quote Link to comment Share on other sites More sharing options...
Gruzin Posted February 11, 2007 Author Share Posted February 11, 2007 Yeeeee! Thanks jesirose, I'am happy Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 Also, if you're trying to find out how many, not just get unique, you can use count() Quote Link to comment Share on other sites More sharing options...
Gruzin Posted February 11, 2007 Author Share Posted February 11, 2007 OK, but DISTINCT works just fine, Thank you again, George Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.