Detailed explanation of where in usage in mysql

There are two cases here

1. After in is a recordset, such as:

select * from table where uname in(select uname from user);

2. In is followed by a string, such as:

select * from table where uname in('aaa',bbb','ccc','ddd','eee',ffff'');

Note: The string must be marked with single quotes '' here;

3. After in is an array, use the following methods, please refer to:

//$pieces is an array with data

for($i=0;$i<count($pieces);$i++){

$uname=$uname."'".$pieces[$i]."',";

}

$the_uname ="uname in(".$uname."'')";

select * from table where ".$the_uname." ;

Remarks: The principle of this method is actually very simple. The second is to program the array in the form of "Case 2" above.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324813542&siteId=291194637