• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

SQL Join Query

Heyas,

I have double table join. I will give you an outline.

select *
From table1
Inner Join ON table2.column1 = table1.column1
Inner Join ON table3.column5 = table1.column5
This part works fine
where table3.address = 'asdf'
and table1.barcode = '1234'

comments:
table3.address is the column5 in table3
table1.barcode is column7 in table1.

The error I get entering the line:
and table1.barcode = '1234'  
The multi-part identifier "table1.barcode " could not be bound.

Is their workaround for this?

Any assistance would be much appreciated thank you.
0
Zack
Asked:
Zack
  • 8
  • 3
  • 2
  • +4
1 Solution
 
David KrollCommented:
Are you sure the field is named "barcode" and not "bar code" or something else?
0
 
ZackGeneral IT Goto GuyAuthor Commented:
Yes I am sure it's labelled barcode.
0
 
David KrollCommented:
Can you run

EXEC sp_help table1

and post the second set of results?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sventhanCommented:
open a new session and try your query again. or, please post describe your table1.
0
 
lluddenCommented:
Can you post the TSQL script to create the tables?
0
 
ZackGeneral IT Goto GuyAuthor Commented:
Hi heyas,

Table 1 has many columns 30 in all.

column1 is an ID column1, column5 (address), column7(barcode)

Can't run in any commands at the moment as I cannot to the database just posting this as query.

Thank you.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
<Inner Join ON >

the code, as posted, is missing the table name in the JOIN part

select *
From table1
Inner Join table2 ON table2.column1 = table1.column1
Inner Join table3 ON table3.column5 = table1.column5

Open in new window

0
 
ZackGeneral IT Goto GuyAuthor Commented:
Hi Angell,

What do you mean?

Thank you.
0
 
ZackGeneral IT Goto GuyAuthor Commented:
The only common column between table3 an table1 in column 5.
0
 
ZackGeneral IT Goto GuyAuthor Commented:
Any other takers.

Thx.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I mean that in the SQL you posted, the TABLE NAME is missing in the JOIN syntax ... between JOIN and ON

you posted:
select *
From table1
Inner Join ON table2.column1 = table1.column1
Inner Join ON table3.column5 = table1.olumn5

I suggested:
select *
From table1
Inner Join table2 ON table2.column1 = table1.column1
Inner Join table3 ON table3.column5 = table1.column5
0
 
Anthony PerkinsCommented:
>>What do you mean?<<
It means your code does not compile.  It is missing code, we need to see the real query.
0
 
ZackGeneral IT Goto GuyAuthor Commented:
Hi Acperkins,

Can't to the database from where I am at the moment.
The structure of the code is as follows.

select *
From table1
Inner Join table2 ON table2.column1 = table1.column1 (Correction thanks to angellll)
Inner Join table3 ON table3.column5 = table1.column5
where table3.address = 'asdf'
and table1.barcode = '1234'

The error I get entering the line:
and table1.barcode = '1234'  
The multi-part identifier "table1.barcode " could not be bound.

Thank you.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you still must not show everything.

one explanation could be that you are using table aliases ...
select *
From table1 t1
Inner Join table2 t2 ON t2.column1 = t1.column1  
Inner Join table3 t3 ON t3.column5 = t1.column5
where t3.address = 'asdf'
and table1.barcode = '1234'   <<< this part would error

fix:
select *
From table1 t1
Inner Join table2 t2 ON t2.column1 = t1.column1  
Inner Join table3 t3 ON t3.column5 = t1.column5
where t3.address = 'asdf'
and t1.barcode = '1234'   <<< this will then work
0
 
ZackGeneral IT Goto GuyAuthor Commented:
No I am using in any tables aliases but I will certainly give that a shot and see if it works.

Thank you.
0
 
Racim BOUDJAKDJIDatabase Architect - Dba - Data ScientistCommented:
@hellworld12345

Your code is not valid TSQL instruction.  Do as angelIII and acperkins suggested.
0
 
ZackGeneral IT Goto GuyAuthor Commented:
Yup that worked my apologies for getting back to your earlier I've been out in the mountains i.e. no net access.

Thanks.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 8
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now