artacus Posted January 18, 2007 Share Posted January 18, 2007 This one is pretty advanced, but I'll give it a shot...I need to join two "sets." So lets say that I have one set (1,2,3,4,5,6) and a second set ('A,B,C,D,E,F') and I want to join them so I should get 36 results '1:A', '1:B', '1:C' thru '6:F'. You can do something like so:[code]SELECT alpha.letter, numeric.numFROM ( SELECT letter FROM alphabet WHERE letter IN ('A','B','C','D','E')) AS alphaJOIN ( SELECT num FROM numbers WHERE num BETWEEN 1 AND 6) AS numeric ON 1 = 1[/code]Thats fine if you've got an alphabet and numbers table lying around that just happens to have the info that you need. But what about an arbitrary set?I'm thinking there should be some way to use EXPORT_SET, FIND_IN_SET, MAKE_SET, IN(), EXPLODE... something! Quote Link to comment https://forums.phpfreaks.com/topic/34800-making-arbitrary-sets/ Share on other sites More sharing options...
fenway Posted January 19, 2007 Share Posted January 19, 2007 I'm confused... by default, join will give you the cartesian product (MxN)... how is what you want different? Quote Link to comment https://forums.phpfreaks.com/topic/34800-making-arbitrary-sets/#findComment-164182 Share on other sites More sharing options...
artacus Posted January 19, 2007 Author Share Posted January 19, 2007 I want to be able to do that when I don't have the data in tables. I gave a simplistic example, what I need is more complicated than 'A,B,C'.So I'm looking for something maybe like this:[code]SELECT *FROM ( SELECT EXPLODE_A_SET('MA70,MA80,MAI1,MAI2,RU1,RU2,MG,AG')) AS MJOIN ( SELECT EXPLODE_A_SET('7,8,9,10,11,12')) AS N ON 1=1[/code]Obviously EXPLODE_A_SET() isn't a real function. But mysql is very good at working with sets when it comes from your tables, so I'm thinking maybe it can do the same w/o the tables. Quote Link to comment https://forums.phpfreaks.com/topic/34800-making-arbitrary-sets/#findComment-164220 Share on other sites More sharing options...
fenway Posted January 22, 2007 Share Posted January 22, 2007 Oh, I see what you mean... let me ponder for a while. Quote Link to comment https://forums.phpfreaks.com/topic/34800-making-arbitrary-sets/#findComment-166706 Share on other sites More sharing options...
fenway Posted January 24, 2007 Share Posted January 24, 2007 I'm thinking of a solution where mutex tables are used... but I'm still thinking. Quote Link to comment https://forums.phpfreaks.com/topic/34800-making-arbitrary-sets/#findComment-168101 Share on other sites More sharing options...
artacus Posted January 25, 2007 Author Share Posted January 25, 2007 mutex? Thats a new one to me. And all I'm finding in the manual is mutex status and mutex locks. Is that similar to a temp table? Quote Link to comment https://forums.phpfreaks.com/topic/34800-making-arbitrary-sets/#findComment-168699 Share on other sites More sharing options...
shoz Posted January 25, 2007 Share Posted January 25, 2007 Although not an elegant solution, If this has to be done in MYSQL you should be able to use UNIONS. I'd imagine that the performance would be fine as well.[code]SELECT*FROM ((SELECT 'a' AS l) UNION (SELECT 'b')) AS lettersINNER JOIN ((SELECT 1 AS n) UNION (SELECT 2)) AS numbers[/code]If you explain the details of the problem perhaps another approach can be suggested. Quote Link to comment https://forums.phpfreaks.com/topic/34800-making-arbitrary-sets/#findComment-168909 Share on other sites More sharing options...
fenway Posted January 25, 2007 Share Posted January 25, 2007 [quote author=artacus link=topic=123053.msg512923#msg512923 date=1169697504]mutex? Thats a new one to me. And all I'm finding in the manual is mutex status and mutex locks. Is that similar to a temp table?[/quote]It's basically just a fake table that you can use to "join" and create "records" for mysql to play with. Quote Link to comment https://forums.phpfreaks.com/topic/34800-making-arbitrary-sets/#findComment-169052 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.