WHERE IN MySQL request

Started by sahildd, Oct 01, 2022, 01:13 AM

Previous topic - Next topic

sahilddTopic starter

Hello.

With the use of IN, I am able to choose the necessary lines that have the logins I have selected in them, utilizing an array known as 'logins'.

$sqlLogin='';
foreach($logins as &$login){
    if($sqlLogin!='')$sqlLogin.=", ";
    $sqlLogin.="'".$login."'";
}
 $sql="SELECT * FROM members WHERE login IN (".$sqlLogin.") ";

However, selecting all entries that do not contain the chosen logins is not clear.
For instance, new rows have appeared in the table (someone else put them there), and a query is needed that will select them.

What is your recommendation on how this can be accomplished?
Also, is it possible to select new records using the auto-increment field (id) present in the table?
  •  

soconsult01

What about NOT IN?

I am uncertain of the criterion needed for a new entry. However, it can be safely assumed that a record with an id of 2 was created after a record with an id of 1. In this case, it is possible to select new records using the auto-increment field (id) present in the table.

This is my preferred and most reliable way of doing this, and I use the following code:

SELECT * FROM table ORDER BY id DESC LIMIT 10
This code outputs the last ten entries in the table.
  •