AshleyKnowles Posted December 14, 2015 Share Posted December 14, 2015 Hi! anyone with some oracle SQL experience? I want to join 2 tables, where the only possible join is by two different columns. Column A is a twelve character long number, while the other ( B ) is a two character long number. They can ba joined, because A is like .BB......... , So the 2. and 3. char is taken from B (and in no other cases this is possible). I think I should be able to use REGEXP_LIKE but how do I use column data in this function? '.column_name.........' isn't working naturaly. I tried to look around but I'm stuck now. The best would be if I can use the column name in the regex. I thought about manually entering the possible number combinations, but that wold require updates, and I can't allow that. Link to comment Share on other sites More sharing options...
Bowmore Posted December 14, 2015 Share Posted December 14, 2015 Somthing like this should work. Select * From TableA a JOIN TableB b on (REGEXP_SUBSTR(a.Column,'^[0-9]{2}') = b.Column)); "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
jchd Posted December 15, 2015 Share Posted December 15, 2015 A regexp isn't needed here :Select * From TableA a JOIN TableB b on (b.Column = substr(a.Column, 2, 2));This should be faster than regexp, and even than LIKE or GLOB argumentum and Skysnake 2 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Skysnake Posted December 17, 2015 Share Posted December 17, 2015 This is easy and simple. Brilliant jchd I would have made a bridge table with a similar kind of sub string select. This is better: simple and a lot more robust. Simple. Fast. Reliable. Would never have though of it myself. Thx for sharing. Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now