On 26 May 2010, at 9:21am, Max Vlasov wrote:

> UPDATE detail_table SET somefield=somevalue
>  WHERE
>  (SELECT masterfieldtocheck FROM master_table WHERE master_table.id
> =detail_table.masterid)=okvalue
> 
> Is there a way to alias the master table when I need to check several fields
> of the master table? Or the only choice is to write
> 
>  WHERE
>  ((SELECT masterfieldtocheck FROM master_table WHERE
> master_table.id=detail_table.masterid)=okvalue)
> AND
>  ((SELECT masterfield2tocheck FROM master_table WHERE master_table.id
> =detail_table.masterid)=okvalue2)

This is why you are using a programming language rather than trying to make SQL 
perform contortions.  Your operation has two parts: one part has nothing to do 
with the detail table, one part has nothing to do with the master table.  
Perform a SELECT command first and use it to work out which masterids qualify.  
You can use 'group_concat()' to reduce the results to one string of values.

SELECT group_concat(id) FROM master_table WHERE [list of master_table qualities 
here]

Then do an UPDATE command which uses that string of values:

UPDATE detail_table SET somefield=somevalue
 WHERE
 detail_table.masterid IN listOfApplicableMasters


Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to