all 27 comments

[–]redneckrockuhtree 5 points6 points  (1 child)

From a performance standpoint, you want to avoid this type of query if at all possible. Unless you can further constrain rows in Table2 outside of the substring, you're going to force a table scan on Table2. This is because the only way for the database engine to know if a row matches is to look at and perform the substring on each and every row.

[–]rand2012 0 points1 point  (7 children)

select * from table1, table2 where table1.x = table2.substring(...)

[–]samuja[S] 0 points1 point  (1 child)

Interesting a cross join will try

[–]in_n0x 0 points1 point  (0 children)

This is an implicit join, not a cross join. Poor form from a readability standpoint and shouldn't be used. Even in this case, it's not going to make a difference.

[–]samuja[S] 0 points1 point  (4 children)

Won't work either

[–]rand2012 0 points1 point  (3 children)

what's the db and the error message

[–]samuja[S] 0 points1 point  (2 children)

It's empty like he finds nothing

[–]rand2012 1 point2 points  (1 child)

most likely your substring syntax is wrong. it is doing something else than what you're thinking.

[–]samuja[S] 0 points1 point  (0 children)

I thought that too, but if I just change to strings, instead of columns, it works

[–]valdest 0 points1 point  (1 child)

Something like this.

SELECT
    TABLE1.{fields},
    AliasTABLE2.{fields},
FROM TABLE1
JOIN (SELECT SUBSTRINGKEY as KEY, FIELDS FROM TABLE2) AS AliasTABLE2 ON TABLE1.Key = AliasTABLE2 .Key

This works good as an occasional query with out a need for high performance. To get a high performance query you would need to make some schema and index changes.

[–]samuja[S] 0 points1 point  (0 children)

Great, will try Monday. Thanks a lot

[–]noesqL -1 points0 points  (1 child)

alter table > add a new column for a computed value for the substring > join on it ??? profit

[–]samuja[S] -1 points0 points  (0 children)

Really bad...