ainoy31 Posted December 18, 2009 Share Posted December 18, 2009 My table columns are as follows userid, service1, service2, service3 and the data type is int(11) So, sample data is userid=34532 / service1_id=564 / service2_id=453 / service3_id=232 The idea is to search the table base on the given userid and pull back the largest value. Which I am able to do. SELECT greatest(service1_id,service2_id,service3_id) FROM devvtest.user_services where userid='$userid') Then, I used the returned value and query the 3 service tables to get user's info. This is where I am stuck. I can run a query for each service as follows: Query for Service1 select legal_name, legal_name_fn, legal_name_ln from service1 where service1_id = (SELECT greatest(service1_id,service2_id,service3_id) FROM devvtest.user_services where userid='$userid' Query for Service2 select legal_name, physical_first_name, physical_last_name from service2 where service2_id = (SELECT greatest(service1_id,service2_id,service3_id) FROM devvtest.user_services where userid='$userid' Query for Service3 select contact_first_name, contact_last_name, legal_business_name from service3 where service3_id = (SELECT greatest(service1_id,service2_id,service3_id) FROM devvtest.user_services where userid='$userid' I am trying to combine these multiple queries into one query. Hope this makes sense. I looked at using if() and no luck. Much appreciation. Quote Link to comment https://forums.phpfreaks.com/topic/185648-query-help/ Share on other sites More sharing options...
fenway Posted December 21, 2009 Share Posted December 21, 2009 Well, you can use OR or a UNION. Quote Link to comment https://forums.phpfreaks.com/topic/185648-query-help/#findComment-981296 Share on other sites More sharing options...
ainoy31 Posted December 21, 2009 Author Share Posted December 21, 2009 Sorry. I figured it out as soon as I posted it on friday and forgot to resolve it. Thanks for the reply. Quote Link to comment https://forums.phpfreaks.com/topic/185648-query-help/#findComment-981614 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.