Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
Showing results for 
Search instead for 
Did you mean: 

I would like to know why CROSS JOIN fails recognize columns

New Contributor III

Whenever I apply a CROSS JOIN to my Databricks SQL query I get a message letting me know that a column does not exists, but I'm not sure if the issue is with the CROSS JOIN.

For example, the code should identify characters such as http, https, ://, / and remove those characters and add the results to a column called websiteurl without the characters aforemention. i.e.

imageThe code is a follows:

SELECT  tt.homepage_url
        ,websiteurl = LEFT(v1.RightString,COALESCE(NULLIF(CHARINDEX('/',v1.RightString)-1,-1),150))
   FROM basecrmcbreport.organizations tt
  CROSS join (VALUES(SUBSTRING(homepage_url,CHARINDEX('//',homepage_url)+2,150)))v1(RightString)

However, the above returns the following:

Error in SQL statement: AnalysisException: Column 'homepage_url' does not exist. Did you mean one of the following? []; line 4 pos 31;
'Project ['tt.homepage_url, unresolvedalias(('websiteurl = 'LEFT('v1.RightString, 'COALESCE('NULLIF(('CHARINDEX(/, 'v1.RightString) - 1), -1), 150))), None)]
+- 'Join Cross
   :- SubqueryAlias tt
   :  +- SubqueryAlias spark_catalog.basecrmcbreport.organizations
   :     +- Relation basecrmcbreport.organizations[uuid#2439,name#2440,type#2441,permalink#2442,cb_url#2443,rank#2444,created_at#2445,updated_at#2446,legal_name#2447,roles#2448,domain#2449,homepage_url#2450,country_code#2451,state_code#2452,region#2453,city#2454,address#2455,postal_code#2456,status#2457,short_description#2458,category_list#2459,category_groups_list#2460,num_funding_rounds#2461,total_funding_usd#2462,... 22 more fields] parquet
   +- 'SubqueryAlias v1
      +- 'UnresolvedSubqueryColumnAliases [RightString]
         +- 'UnresolvedInlineTable [col1], [['SUBSTRING('homepage_url, ('CHARINDEX(//, 'homepage_url) + 2), 150)]]

Any thoughts on how to fix this?


Not applicable

The underscore in the column name might be problematic, so try to put the column name in back ticks like `homepage_url`.

Would it be easier to use a regexp_extract instead of a cross join?

New Contributor III

Hi Joesphk,

Thanks for reaching out.

I tried your suggestion with the back ticks, however, I'm still getting the same error

Esteemed Contributor III

I think you can achieve it without CROSS JOIN.

Please check your query step by step so you will find error.

Not applicable


Hope all is well!

Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help. 

We'd love to hear from you.


Honored Contributor


Since you have given an alias "tt" to your table "basecrmcbreport.organizations", to access corresponding columns you will have to access them in format tt.<column_name>

in your code in line #4, try accessing the column 'homepage_url' along with table alias.

Example: "tt.homepage_url"

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!