I have two tables in database:
comments table users table
| u_id | text | | u_id | premium |
| 9 | .. | | 9 | 1 |
| 10 | .. | | 10 | 0 |
| 9 | .. |
I want to select text from comments table for user in case only when this user has premium status (1). But if I want to check status of this user I need do another mysql query. Is this possible to do check that in one query?
$premium=sql_select("SELECT premium FROM users WHERE u_id LIKE '".$_GET['u_id']."'");
if ($premium[1][0]=1) {
$text=mysql_query("SELECT text FROM comments WHERE u_id LIKE '".$_GET['u_id']."'");
}
else //this user has no premium account so text will not be selected.
Use an (inner) join: