lpa wrote:My users table have unique uid values. This is another table just for searching purposes - to find people by name, surname, name and surname or nickname.
The main user table there are 3 columns for names/surnames/nicknames: name, surname, nickname. To find people it's necessary to run a comlicated query:
select * from users where name='$search%' or surname='$search%' or nickname='$search%' ... and search term can be not just a single word but also name+surname or surname+name combination...
so, I created one more table that contains all names, surnames and nicknames. Now I can search easier
select from table2 where txt like '$search%'
Ah, then you have an alternative that is directly derived from your usual query:
SELECT COUNT(*) FROM users WHERE uid IN (SELECT uid FROM table2 WHERE txt LIKE '$search%');
However, I am inclined to think that this remains simpler:
SELECT COUNT(DISTINCT uid) FROM table2 WHERE txt LIKE '$search%';
lpa wrote:I don't remember where dod I read that DISTINCT is not recommended. But Google finds a lot of questions about DISTINCT. For example here
The fact that there are many such articles does not mean much: if you actually read those articles, you would see that they do not apply to you. The article that you gave as an example notes that this has to do with a bug in MySQL, so whether or not it applies to you depends on whether you are affected by the bug: changing your code to preemptively avoid such a bug would be foolish as you could well run into another bug, so you should test if you are concerned.