Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SELECT and SELECT DISTINCT problem

Author  Topic 

exopolitix
Starting Member

1 Post

Posted - 2009-11-03 : 12:32:56
Hi.

I am new to SQL, I am trying to insert information from one already made table into a set of tables I have created. For example my code is laid out similiar to this:

INSERT INTO **mytable**
SELECT DISTINCT *value*, *value2*
FROM **premade table**;

The only problem I have is that when I have a primary and a foreign key in a table it wont work. I think its because of the DISTINCT and it will only let the foreign keys be displayed once also. So basically I think (im not really to sure about it) I want a SELECT DISTINCT for my primary key and then SELECT for the rest. But when I try to do this it moans that my first statement does not have enough values.

Any insight into this would be really really helpful. Cheers.

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-11-03 : 13:05:31
I'm not sure I understand the problem well enough. Perhaps if you can supply us with DDL, Data and expected output we can help better:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page
   

- Advertisement -