Help with querey!!
I am trying to select values from 2 tables, but filter the records returned by value in another table (via sub querey). It works great when there is a value found in that 3rd table. But when there is no value found in the third table, instead return all records in tables 1 and 2, I get nothing. please help, asap.
querey:
select *
from test, category
where test_category_id = category_id
and test_id != (select utest_test_id from utest where utest_user_id = 3)
order by test_id
tables:
mysql> select * from test;
+---------+--------------------+----------------+------------------+-----------------+
| test_id | test_name | test_num_quest | test_category_id | test_time_limit |
+---------+--------------------+----------------+------------------+-----------------+
| 1 | Sample Test | 1 | 1 | 20 |
| 2 | Security Awareness | 2 | 2 | 30 |
+---------+--------------------+----------------+------------------+-----------------+
2 rows in set (0.00 sec)
mysql> select * from category;
+-------------+-----------------+
| category_id | category_name |
+-------------+-----------------+
| 1 | Sample Category |
| 2 | Security |
+-------------+-----------------+
2 rows in set (0.00 sec)
mysql> select * from utest;
+----------+---------------+---------------+---------------------+-------------+------------------+
| utest_id | utest_user_id | utest_test_id | utest_date | utest_score | utest_time_spent |
+----------+---------------+---------------+---------------------+-------------+------------------+
| 1 | 2 | 2 | 2006-07-20 13:58:59 | 1 | 4 |
+----------+---------------+---------------+---------------------+-------------+------------------+
1 row in set (0.00 sec)
|