Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

help with query

Posted on 2013-06-06
4
Medium Priority
?
315 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:Ernesto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 22

Accepted Solution

by:
Om Prakash earned 2000 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 66

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

721 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