Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SQL ambiguous column how to solve explained with query

SQL Ambiguous Column How To Solve Explained With Query

The name Ambiguous column is very common error in SQL. I found many scenarios where people or developers confused with this error.

The ambiguous columns means – SQL does not understand which column it has to consider. SQL boot-camp is really good to know all these things.

Let me explain in detail…

In a classroom there are two boys with same name…

Okay…

If teacher calls the name, both boys look up their head. So, it is confusion to teacher and the class room…..students who are sitting inside.

So, teacher made some change…

Added some uniqueness to each boy name…

Then, problem is resolved.

Enter your email address to follow this blog and receive notifications of new posts by email.

SQL Query

SELECT invoice_numb, 
       vendor_name 
FROM   vendors 
       INNER JOIN invoices 
               ON vendor_id = vendor_id 
ORDER  BY invoice_numb;  

In the above query, the incorrectness is you are joining on vendor_id. The problem is vendor_id is present in both the tables.

This is called ambiguous.

The modified query is…

 SELECT invoice_numb, 
       vendor_name 
FROM   vendors 
       INNER JOIN invoices 
               ON vendors.vendor_id = invoices.vendor_id 
ORDER  BY invoice_numb;  

Also read,

32 Tricky SQL queries you need for all interviews



This post first appeared on Srinimf - Tech.Jobs.Biz.Success, please read the originial post: here

Share the post

SQL ambiguous column how to solve explained with query

×

Subscribe to Srinimf - Tech.jobs.biz.success

Get updates delivered right to your inbox!

Thank you for your subscription

×