Jump to content

complex query


adzie

Recommended Posts

Is it possible to run this query.

 

each user has a group ID for example

 

abc0003A the ABC indentifies the group 0003 identifies the user and A identifies the location of the user

 

I'd like to run a query which identifies members by the group and then can break those members down again by location

 

I suspect this is not possible due to the 0003 in the middle.

 

I'll include a idea of how the database looks so you can tell me if its possible

 

member id name email password type userid

 

100001 john [email protected] password 1 egc0001A

100002 sam [email protected] password 1 egc0002B

100003 anne [email protected] password 4 abc0003A

100004 sally [email protected] password 1 egc0004D

100005 mike [email protected] password 3 def0005C

100006 tom [email protected] password 3 def0006A

100007 keith [email protected] password 2 reg0007D

 

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

Sure,

 

Prolly someone smart like Barand could do it in one query with substrings alone, but I'll take a crack at it...

 

first select based on the substring of the abc the shoot off query from within the results with the other substring

 

select * from table where subst(`field`,0,3)='egc' and subst(`field`,-2,2) = '1A' from table...

 

would find [email protected]'s record

 

Link to comment
https://forums.phpfreaks.com/topic/69745-complex-query/#findComment-350428
Share on other sites

Im not entirely sure how you want to 'group those members by location again'

 

If you were to run a query such as:

SELECT *,SUBSTRING(`userid`,-1) AS location FROM `users` WHERE SUBSTRING(`userid`,1,3)='egc' ORDER BY location

 

You'd then have all the users with a particular group (egc in this case), ordered by their location. When you outputted the results, you could then group the users together by location by ending each 'group' when the location changes.

Link to comment
https://forums.phpfreaks.com/topic/69745-complex-query/#findComment-353468
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.