Question: i have the fowling code in my project:

```
 $title = "In this title we have the word GUN"
 $needed_words = array('War', 'Gun', 'Shooting');
 foreach($needed_words as $needed_word) {
     if (preg_match("/\b$needed_word\b/", $title)) {
     $the_word = "ECHO THE WORD THATS FIND INSIDE TITLE";
     }
 }

```

I want to check if `$title` contains one of 15 predefined words, 
for example lets say:
if `$title` contains words **"War, Gun, Shooting"** then i want to assign the word that is find to `$the_word`

Thanks in advance for your time!

Answer: 
The trick, of course, is knowing how to combine the two parts of the query:

```
SELECT user_password.UserName, user_password.Password, COUNT(*)
FROM user_password
JOIN (SELECT UserName
      FROM user_password
      GROUP BY UserName
      HAVING COUNT(DISTINCT Password) > 1) multiple_passwords
  ON multiple_passwords.UserName = user_password.UserName
GROUP BY user_password.UserName, user_password.Password
ORDER BY user_password.UserName

```

(Have a [working SQL Fiddle demo](http://sqlfiddle.com/#!4/ba9ae/6)!) 

The sub-select (inner query) finds `UserName`s with more than one password (and gets unique rows, too). Outside of that, it's a standard "count of times entry is reused" query.

(And by the way, I hope these aren't real passwords... #shudders#)
this should work: 

```
SELECT username,password,COUNT(*)
FROM t
WHERE username IN (SELECT username FROM t GROUP BY username HAVING COUNT(DISTINCT password>1))
GROUP by username,password

```

you can optimize it if you'll use with clause to prevent the table from being read twice.