0

I need to join 2 tables together on the 'URL' column, however because of some crazy problems on our back-end, the URLs get logged inconsistently (slash/no-slash) in the two tables: http://google.com/ vs. http://google.com.

After I run my query to join, I get:

URL                     DATE
http://facebook.com     20130914
http://google.com/      NULL
http://youtube.com/     NULL

I'm a beginner with SQL, but does SQL have something like after you run a query, IF item in column is empty, then run query again?

I found How to ignore trailing slash while joining two string columns in SQL that I can then modify the 2nd query to remove trailing slash if exist.

3
  • 2
    What does your query look like? Why not join using rtrim(col,'/')? Not efficient, but probably more efficient than querying twice. Commented Oct 7, 2013 at 23:12
  • @BarbaraLaird: the reason is because I only want to rtrim if what it returned null on the first pass Commented Oct 7, 2013 at 23:32
  • SELECT DISTINCT b.url AS url, a.date AS date FROM url_results a LEFT OUTER JOIN url_samples b ON b.url = a.url; Commented Oct 8, 2013 at 0:02

1 Answer 1

1

Unfortunately, your best best course of action is to cleanup the data and normalize it on insert. The problem here is that you are performing a join with this data. Any work around will be very inefficient from a performance perspective.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.