Forum Discussion
NEED HELP IN SQL
- Anonymous3 years ago
Hi TANVIP ,
Here is the SQL query to get the desired result:
SELECT ID, Value FROM contact WHERE ContactCategoryId = (SELECT ContactCategoryId FROM contactcategory WHERE type = 'phone') UNION SELECT ID, Value FROM contact WHERE ContactCategoryId = (SELECT ContactCategoryId FROM contactcategory WHERE type = 'mobile')This query will first select all the entries with ContactCategoryId of 'phone' and then all the entries with ContactCategoryId of 'mobile' if there are no entries with ContactCategoryId of 'phone'.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi TANVIP ,
Here is the SQL query to get the desired result:
SELECT ID, Value
FROM contact
WHERE ContactCategoryId = (SELECT ContactCategoryId FROM contactcategory WHERE type = 'phone')
UNION
SELECT ID, Value
FROM contact
WHERE ContactCategoryId = (SELECT ContactCategoryId FROM contactcategory WHERE type = 'mobile')
This query will first select all the entries with ContactCategoryId of 'phone' and then all the entries with ContactCategoryId of 'mobile' if there are no entries with ContactCategoryId of 'phone'.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.