1

I'm trying to join 2 tables and getting this error.

About schema: PK's are a.app_guid, s.space_guid, o.org_guid.

The multi-part identifier "apps.space_guid" could not be bound

SELECT 
    a.app_guid,
    a.name,
    a.state,
    a.created_at,
    a.updated_at,
    deleted_at,
    a.space_guid,
    a.foundation,
    a.timestamp, 

    s.space_guid,
    s.name,
    s.created_at,
    s.updated_at,
    s.timestamp,
    s.foundation,
    s.org_guid, 

    o.org_guid,
    o.created_at,
    o.updated_at,
    o.name,
    o.timestamp,
    o.foundation
FROM 
    apps a, spaces s, organizations o
INNER JOIN 
    [spaces] ON [apps].[space_guid] = [spaces].[space_guid]
INNER JOIN 
    [organizations] ON [spaces].[org_guid] = [organizations].[org_guid]

The expected result will include a table where its all combine according to space_guid and org_guid

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sam
  • 471
  • 7
  • 24
  • If you define an alias for a table then you have to use it. For instance replace `[apps].[space_guid]` with `a.[space_guid]` – juergen d Aug 23 '19 at 20:21
  • Don't mix the old, deprecated "comma-separated tables in `FROM`" style with the new, **proper** ANSI JOIN style - use the **new**, proper ANSI style **only** - and don't join each of the tables twice...... – marc_s Aug 23 '19 at 20:24
  • its not working still the same error – Sam Aug 23 '19 at 20:24
  • Is this your actual code? Are you really cross joining 3 tables and then inner join 2 more? Don't you have a WHERE clause? – forpas Aug 23 '19 at 20:27
  • @forpas I just need to join everything together I don't need where clause – Sam Aug 23 '19 at 20:33
  • @Sam see my answer – forpas Aug 23 '19 at 20:33

1 Answers1

2

I don't think that you want to cross join and inner join the tables.
You just messed the syntax.
Use this proper join syntax:

SELECT 
    a.app_guid,
    a.name,
    a.state,
    a.created_at,
    a.updated_at,
    deleted_at,
    a.space_guid,
    a.foundation,
    a.timestamp, 

    s.space_guid,
    s.name,
    s.created_at,
    s.updated_at,
    s.timestamp,
    s.foundation,
    s.org_guid, 

    o.org_guid,
    o.created_at,
    o.updated_at,
    o.name,
    o.timestamp,
    o.foundation
FROM 
    apps a
INNER JOIN 
    spaces s ON a.space_guid = s.space_guid
INNER JOIN 
    organizations o ON s.org_guid = o.org_guid
forpas
  • 160,666
  • 10
  • 38
  • 76