explanation: you cannot mix joins and listing tables like that.
Main Topics
Browse All TopicsDear All,
Having just upgraded to SQL Server 2005, some of the SQL syntax used in my application has broken (namely the non-ANSI *= joins). I have replaced these with LEFT OUTER JOIN syntax until it worked successfully under an old compatibility mode, and then moved to (90). However, I now get the following error:
Msg 107, Level 16, State 2, Line 1
The column prefix 'p' does not match with a table name or alias name used in the query.
with the following script (excuse poor formatting, copied and pasted from a Web App output trace):
select p.paper_id,p.title,a.last_
p.publication_date,u.publi
from paper p, publication u, organisation o
left outer join author a on p.primary_author_id = a.author_id
where p.publication_id = u.publication_id
and p.organisation_id = o.organisation_id
and p.title like '%binhi%'
order by p.publication_date desc
If I comment out the joins, the script works as follows:
select p.paper_id,p.title,--a.las
p.publication_date,u.publi
from paper p, publication u, organisation o
--left outer join author a on p.primary_author_id = a.author_id
where p.publication_id = u.publication_id
and p.organisation_id = o.organisation_id
and p.title like '%binhi%'
order by p.publication_date desc
But I cannot see anything obvious wrong with the join itself.
Any help would be greatly appreciated,
Best Regards,
- Graham
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I suggest you try to take away the *and p.title like '%binhi%* from the inner join definition and put it in the condition. THe same way I suggest you do not express inner join condition by where conditions...Which would come to something like...
select p.paper_id,p.title,--a.las
p.publication_date,u.publi
from paper p inner join publication u
on p.publication_id = u.publication_id
inner join organisation o
on p.organisation_id = o.organisation_id
where p.title like '%binhi%'
order by p.publication_date desc
<<Sorry to continue this one after solution. Is it fair to say that it is worth updating all inner joins to be in the FROM clause instead of the WHERE clause from now on ?>>
Yes.
If I am not mistaken, SQL 92 (or 99?) SQL standard encourages the idea that the correct way of writing JOIN conditions should be under the form :
"...table1 inner join table2 on table1.ID = table2.ID"
instead of the old "..table1, table2 where table1.ID = table2.ID".
That has the following advantages:
> Separating WHERE conditions helps modularize better the select statement
> Optimization is easier
> Code more readable
Hope this helps...
Business Accounts
Answer for Membership
by: angelIIIPosted on 2007-01-25 at 03:12:58ID: 18394460
select p.paper_id,p.title,a.last_ name,a.fir st_name, cation_nam e,p.public ation_id
p.publication_date,u.publi
from paper p
join publication u
on p.publication_id = u.publication_id
join organisation o
on p.organisation_id = o.organisation_id
left outer join author a on p.primary_author_id = a.author_id
where p.title like '%binhi%'
order by p.publication_date desc