Subquery Help Please :-Þ

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

Subquery Help Please :-Þ

Post 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.
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

Re: Subquery Help Please :-Þ

Post 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
Post Reply