I am creating a new table in a database called ‘production’ by joining data from two tables in another database called ‘crawler’. I create this new table with the following SQL query ( this query works perfectly ):
CREATE TABLE files_and_metas_joined
SELECT
crawler.files.id,
crawler.files.company_id,
crawler.file_metas.title,
crawler.file_metas.h1_tags
FROM
crawler.files,
crawler.file_metas
WHERE
crawler.files.id = crawler.file_metas.file_id
AND
crawler.files.processed = 1
AND
crawler.files.junk = 0
I’d like to also add the following indexes to this table but can’t seem to figure out how to do it in the same SQL query.
PRIMARY KEY (`id`),
KEY `company_id` (`company_id`),
KEY `title` (`title`),
KEY `h1_tags` (`h1_tags`)
Can this be done in the same query used to create the table? If not, how do I add these indexes with a query afterwards?
You can do it in the same statement, they just have to go before the
SELECT: