Search code examples
mysqlsqlinto-outfile

mysql - select * from tableA, tableB - problem


is this a valid mysql statement ?

select * from TableA , TableB ;

if not what is the correct mysql statement for selecting the two tables.

why i think there's something wrong with this is i wrote a mysql statement

select * from TableA, TableB INTO OUTFILE 'c:/test.csv' FIELDS TERMINATED BY ','  ENCLOSED BY '"'  LINES TERMINATED BY '\n' ;

and it went to endless loop . when i terminated. the csv file had grown into GBs in size.


Solution

  • If you only want to take all of the records of TableA and then all of the records from TableB in sequential order, the union keyword might be of interest.

    SELECT * FROM TableA
    UNION
    SELECT * FROM TableB 
        INTO OUTFILE 'c:/test.csv' 
        FIELDS TERMINATED BY ','  
        ENCLOSED BY '"'  
        LINES TERMINATED BY '\n' ;