Page 1 of 1

using INSERT and SELECT DISTINCT

Posted: Sat Jun 17, 2006 1:10 pm
by duk
hy guys

if we want to INSERT into a table 3 values, and 1 of them at this query need to be always 1, and the SELECT DISTINCT we gona use just get 2 values, and the third one need to be 1 how can i do this ???

this is the query:

Code: Select all

mysql> insert into cidpid (pid,cid,lider) select distinct members.pid,clans.cid
from members,clans where clans.pid_criador='3nrq74z';
but, the value for lider, dont come from the SELECT DISTINCT need to be 1 in this query but i cant figure how to insert it :(

Posted: Sat Jun 17, 2006 2:18 pm
by printf
I really don't understand what your doing, but if your SELECT, is only returning 2 results and you need 3 for the INSERT, then just put the value you need in the SELECT part of your query!

A simple example..... ( SELECT 2 values add the third value => 1 )

Code: Select all

INSERT INTO tablea (pid, cid, lider) SELECT fielda, fieldb, 1 FROM tableb WHERE some_column = some_value;

Notice I inserted the value (1) after fieldb => , 1, I am only selecting fielda, fieldb and using (1) as the third value for the insert!


pif

Posted: Sat Jun 17, 2006 3:33 pm
by duk
nice

thansk a lot m8..