Jump to content

Query Help


ainoy31

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/185648-query-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.