Table Name: contacts_tbl
Challenge :
make use of the above two tables and write the search query to list names of all persons belong to particular group
e.g., if I search for group 'Friends' it should list names of records 1,2,3,8,9,11,12,13 from contacts_tbl
post your query in comment section...
. Del.icio.us Add to del.icio.us Digg DiggIt! Reddit Reddit Stumbleupon Stumble This Google Bookmarks Add to Google Bookmarks Yahoo My Web Add to Yahoo MyWeb Technorati Add to Technorati Faves Slashdot Slashdot it




8 comments:
post select query here...
select contacts_tbl.name from contacts_tbl where group_id=(select id from groups_tbl where groups_tbl.name='Friends')
SELECT * FROM `contacts_tbl` WHERE group_id like '%9' Or group_id like '9%' Or group_id = '9'
if am searching for group friends.
Mr. Anonymous your query can carry only 3 records, the records which have group_id exactly equal to 9 and the records which starts with 9. If you are searching Friends group it should list out 8 records!
Hello Ajax... your query will list out all the records which contains 9 in group_id, it'll list 19, 99 also... be more specific man.
SELECT name FROM `contacts_tbl` WHERE group_id like '%,9' Or group_id like '9,%' Or group_id = '9'
MySQL you missed 1 condition. Your query will fetch 5 records 1,2,3,5,9 only...
Correct Query: SELECT name FROM `contacts_tbl` WHERE group_id like '%,9' Or group_id like '9,%' Or group_id like '%,9,%' Or group_id = '9'
Post a Comment