Solved

SQL Join Query

Posted on 2011-09-30
17
202 Views
Last Modified: 2012-05-12
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
Comment
Question by:Zack
  • 8
  • 3
  • 2
  • +4
17 Comments
 
LVL 11

Expert Comment

by:David Kroll
ID: 36891532
Are you sure the field is named "barcode" and not "bar code" or something else?
0
 

Author Comment

by:Zack
ID: 36891574
Yes I am sure it's labelled barcode.
0
 
LVL 11

Expert Comment

by:David Kroll
ID: 36891614
Can you run

EXEC sp_help table1

and post the second set of results?
0
 
LVL 18

Expert Comment

by:sventhan
ID: 36891616
open a new session and try your query again. or, please post describe your table1.
0
 
LVL 18

Expert Comment

by:lludden
ID: 36891619
Can you post the TSQL script to create the tables?
0
 

Author Comment

by:Zack
ID: 36891658
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36891662
<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
 

Author Comment

by:Zack
ID: 36891673
Hi Angell,

What do you mean?

Thank you.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:Zack
ID: 36891684
The only common column between table3 an table1 in column 5.
0
 

Author Comment

by:Zack
ID: 36891747
Any other takers.

Thx.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36891944
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36895113
>>What do you mean?<<
It means your code does not compile.  It is missing code, we need to see the real query.
0
 

Author Comment

by:Zack
ID: 36895453
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
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 36895991
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
 

Author Comment

by:Zack
ID: 36896029
No I am using in any tables aliases but I will certainly give that a shot and see if it works.

Thank you.
0
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
ID: 36896277
@hellworld12345

Your code is not valid TSQL instruction.  Do as angelIII and acperkins suggested.
0
 

Author Closing Comment

by:Zack
ID: 36923609
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
set default date format in mssql to mm/dd/yyyy 22 66
SQL Union 20 44
Upgrading an old legacy SQL server 20082 to 2014 - TSQL compatibility 3 36
TSQL - IF ELSE? 3 25
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now