SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Matching Missing Field


Matching Missing Field

Author
Message
Mark Grout
Mark Grout
SSC-Addicted
SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)

Group: General Forum Members
Points: 476 Visits: 158
Comments posted to this topic are about the item Matching Missing Field
Lokesh Vij
Lokesh Vij
SSCertifiable
SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)

Group: General Forum Members
Points: 7562 Visits: 1600
I did observed this strange behavior, but was not aware of the reason behind this. Thanks :-)

~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter


angeloc
angeloc
SSC Journeyman
SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)

Group: General Forum Members
Points: 89 Visits: 90
well that's interesting. Certainly wouldn't want to rely on it, unless that is behavior in the standard.
demonfox
demonfox
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4597 Visits: 1192
Lokesh Vij (1/16/2013)
I did observed this strange behavior, but was not aware of the reason behind this. Thanks :-)

+1
good question ..thanks...

~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one Ermm
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (193K reputation)SSC Guru (193K reputation)SSC Guru (193K reputation)SSC Guru (193K reputation)SSC Guru (193K reputation)SSC Guru (193K reputation)SSC Guru (193K reputation)SSC Guru (193K reputation)

Group: General Forum Members
Points: 193355 Visits: 18674
EZ PZ

Thanks

Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Learn Extended Events

Ajay Reddy
Ajay Reddy
Right there with Babe
Right there with Babe (726 reputation)Right there with Babe (726 reputation)Right there with Babe (726 reputation)Right there with Babe (726 reputation)Right there with Babe (726 reputation)Right there with Babe (726 reputation)Right there with Babe (726 reputation)Right there with Babe (726 reputation)

Group: General Forum Members
Points: 726 Visits: 262
Good Question

thanks

Thanks&Regards
AJAY REDDY.L

Stuart Davies
Stuart Davies
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13533 Visits: 4878
Good question - thanks

-------------------------------Posting Data Etiquette - Jeff Moden Smart way to ask a questionThere are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan I would never join a club that would allow me as a member - Groucho Marx
Hugo Kornelis
Hugo Kornelis
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44801 Visits: 13557
Dang! You stole my thunder... I thought up a similar question about a week ago, just didn't get around to submitting it yet...

Thanks! Wink


angeloc (1/16/2013)
well that's interesting. Certainly wouldn't want to rely on it, unless that is behavior in the standard.

Yes, this is standard. And yet, I still would not rely on it. Imagine how your query would suddenly fail if someone adds a column "col1" to table "TblA2"!
For any query that uses more than a single table, you should always use the table prefix on ALL column references. (And because most table names tend to be long and I prefer my query to be human readable, this automatically implies that you should also always provide an alias for each of the tables used in the query.


Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Dineshbabu
Dineshbabu
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2310 Visits: 569
Great question and great concept.

I added COL1 to TblA2 and expected "Ambiguous column name 'col1'.". But this time Sql server selected column from TblA2 and gave me the correct result.

It will be failed in Joins if we didn't prefix the table with alias name.

But as Hugo said, we can't predict the output if someone add col1 after sometime. So always it is better to prefix the columns with table alias name.

--
Dineshbabu
Desire to learn new things..
Hugo Kornelis
Hugo Kornelis
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44801 Visits: 13557
Dineshbabu (1/17/2013)
Great question and great concept.

I added COL1 to TblA2 and expected "Ambiguous column name 'col1'.". But this time Sql server selected column from TblA2 and gave me the correct result.

It will be failed in Joins if we didn't prefix the table with alias name.

That's correct. SQL Server will first try to match an unqualified column reference in the current scope. If that fails, it will go one scope higher, and repeat that as necessary. You will only get the "ambiguous column name" error if there are multiple columns with the same name at the same level.


Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search