MySQL Forums
Forum List  »  Newbie

Breaking up MYSQL code
Posted by: Trey Taylor
Date: April 14, 2015 10:01AM

Hey all,

Is there a way to break up MYSQL code into multiple sections, I have code that has multiple SELECTs and I'd like to keep it all in one query that when clicked does what I want, but because there's multiple SELECTs it doesn't 100% work.

A base example of my code:

SET @var1:= 4;
SET @var2:= 1;
SET @var3:= 7;
SET @var4:= 8;

SELECT *

INTO OUTFILE 'path/to/folder'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'

FROM table AS T1

LEFT JOIN table2 AS T2
ON T.`fieldid` = T2.`fieldid`

LEFT JOIN table3 AS T3
ON T2.`fieldid` = T3.`fieldid`

LEFT JOIN table4 AS T4
ON T4.`fieldid` = T2.`fieldid`

WHERE T.field = @ACTIVE
AND T2.`field` = @ACTIVE
AND T2.`field` = @var2
AND T3.`field` IS NOT NULL

SELECT *

INTO OUTFILE 'path/to/folder2'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'

FROM table AS T1

LEFT JOIN table2 AS T2
ON T.`fieldid` = T2.`fieldid`

LEFT JOIN table3 AS T3
ON T2.`fieldid` = T3.`fieldid`

LEFT JOIN table4 AS T4
ON T4.`fieldid` = T2.`fieldid`

WHERE T.field = @ACTIVE
AND T2.`field` = @ACTIVE
AND T2.`field` = @var3
AND T3.`field` IS NOT NULL


How can I break it up so it executes one block of code and then the other statement?

Any help is much appreciated!

-Trey

Options: ReplyQuote


Subject
Written By
Posted
Breaking up MYSQL code
April 14, 2015 10:01AM
April 14, 2015 11:11PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.