Solved

help with query

Posted on 2013-06-06
4
303 Views
Last Modified: 2013-06-06
hi guys
why this query do not work

INSERT INTO suplementos(numdeord)SELECT DISTINCT numdeord FROM odc LEFT JOIN suplementos ON odc.numdeord=suplementos.numdeord WHERE suplementos.numdeord IS NULL

error
ambigous column name

tsm
0
Comment
Question by:edo60
4 Comments
 
LVL 22

Accepted Solution

by:
Om Prakash earned 500 total points
ID: 39226334
try:

INSERT INTO
suplementos (numdeord)
SELECT
      DISTINCT
            odc.numdeord
      FROM odc
      LEFT JOIN suplementos
      ON odc.numdeord=suplementos.numdeord WHERE suplementos.numdeord IS NULL
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39226343
>ambigous column name
That's because numderord exists in both odc and suplementos tables, and T-SQL doesn't know which one you want to insert, and won't assume for you.

INSERT INTO suplementos(numdeord)SELECT DISTINCT odc.numdeord FROM odc LEFT JOIN suplementos ON odc.numdeord=suplementos.numdeord WHERE suplementos.numdeord IS NULL

or

INSERT INTO suplementos(numdeord)SELECT DISTINCT suplementos.numdeord FROM odc LEFT JOIN suplementos ON odc.numdeord=suplementos.numdeord WHERE suplementos.numdeord IS NULL
0
 
LVL 11

Expert Comment

by:Simone B
ID: 39226347
You need to specify where you're getting numdeord from:

INSERT INTO suplementos(numdeord)
SELECT DISTINCT odc.numdeord
FROM odc
LEFT JOIN suplementos ON odc.numdeord=suplementos.numdeord WHERE suplementos.numdeord IS NULL
0
 
LVL 4

Expert Comment

by:BAKADY
ID: 39226380
Try:

INSERT suplementos ( numdeord )
SELECT odc.numdeord
FROM odc LEFT JOIN suplementos
    ON odc.numdeord = suplementos.numdeord
GROUP BY odc.numdeord
HAVING COUNT( suplementos.numdeord ) = 0

Saludos
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

832 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