Page 1 of 1

Subquery Help Please :-Þ

Posted: Mon Jan 21, 2008 1:58 pm
by afbase
I have two tables with the same exact columns. I want to insert all data from all columns from table 1 (curldata) to table 2 (coldowl) IF the value of 'ticker' does not exist in table 2 and it meets specified parameters. So far this is what i have:

[sql] IF NOT EXISTS (SELECT 'ticker'FROM curldataWHERE annsales >= '100'AND multiplier <= '17'AND multiplier > '0'AND bookval > '0'AND multiplier * bookval <= '24.5'AND past_5_earnings >= '16.5'AND curass / total_cur_liabilities >= '2')INSERT INTO 'coldowl' (SELECT *FROM curldataWHERE annsales >= '100'AND multiplier <= '17'AND multiplier > '0'AND bookval > '0'AND multiplier * bookval <= '24.5'AND past_5_earnings >= '16.5'AND curass / total_cur_liabilities >= '2' ) ; [/sql]
This is my first subquery attempt. Any help is appreciated.

Re: Subquery Help Please :-Þ

Posted: Mon Jan 21, 2008 2:20 pm
by afbase
I've revised the query as so. Hopefully this 'idea' makes more sense than the previous sql attempt I posted:

[sql] IF( SELECT 'ticker'FROM curldataWHERE annsales >= '100'AND multiplier <= '17'AND multiplier > '0'AND bookval > '0'AND multiplier * bookval <= '24.5'AND past_5_earnings >= '16.5'AND curass / total_cur_liabilities >= '2' ) NOTEXISTS IN 'coldowl.ticker'THEN (INSERT INTO coldowl( * )VALUES (SELECT *FROM curldataWHERE annsales >= '100'AND multiplier <= '17'AND multiplier > '0'AND bookval > '0'AND multiplier * bookval <= '24.5'AND past_5_earnings >= '16.5'AND curass / total_cur_liabilities >= '2')) [/sql]

note: this is mysql 5.0