Like Joins, Sub-queries can be used to move some of the logic from PHP into the database engine.

<?php
$b 
sqlite_array_query($db,
    
"SELECT * FROM bar WHERE id=(SELECT id FROM foo WHERE name='ilia')");
?>
In MySQL, the full support for sub-queries starts from version 4.1

In many instances it is better to use Joins rather then sub-queries.