Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql select into new table

-- Insert into existing my_table
INSERT INTO my_table my SELECT * FROM another_table an WHERE an.col1 > 10;
-- or directely create the new table
CREATE TABLE my_table AS SELECT * FROM another_table an WHERE an.col1 > 10;
Comment

mysql select into new table

CREATE TABLE artists_and_works
  SELECT artist.name, COUNT(work.artist_id) AS number_of_works
  FROM artist LEFT JOIN work ON artist.id = work.artist_id
  GROUP BY artist.id;
Comment

mysql create table from select statement

select * into <NEW_TABLE_NAME> from <OLD_TABLE>;
Comment

create table from query mysql

CREATE TABLE prices_published_april_25 
SELECT prices_held_feb_3_2022.id,prices_held_feb_3_2022.unique_batch_id,prices_held_feb_3_2022.commodity_id,prices_held_feb_3_2022.variety_id,prices_held_feb_3_2022.price1,prices_held_feb_3_2022.price2,prices_held_feb_3_2022.price3,prices_held_feb_3_2022.price4,prices_held_feb_3_2022.price5,prices_held_feb_3_2022.availability_type_id,prices_held_feb_3_2022.grade_id,prices_held_feb_3_2022.batch_id,prices_held_feb_3_2022.user_id,prices_held_feb_3_2022.unit_id,prices_held_feb_3_2022.created_at,prices_held_feb_3_2022.updated_at,batches.batch_date,batches.published_date,batches.is_published,commodities.commodity,commodities.type_id AS commodity_type_id FROM `prices_held_feb_3_2022` 
inner join `batches` on `prices_held_feb_3_2022`.`batch_id` = `batches`.`id` 
inner join `commodities` on `prices_held_feb_3_2022`.`commodity_id` = `commodities`.`id` 
WHERE `batches`.`is_published` = 'YES' 
order by `commodities`.`commodity` asc
Comment

PREVIOUS NEXT
Code Example
Sql :: mysql select statement after index 
Sql :: oracle dependencies table 
Sql :: how to ascending order in sql 
Sql :: oracle insert into where 
Sql :: change column data type sql 
Sql :: Client does not support authentication protocol requested by server; consider upgrading MySQL client 
Sql :: sql if example 
Sql :: replace divide by zero error with 0 in sql 
Sql :: find number of entries sql 
Sql :: SQL COUNT() With HAVING Clause 
Sql :: mysql import from sql file 
Sql :: rename column mysql 
Sql :: uppercase sql 
Sql :: sql query to select data between two dates 
Sql :: mysql create user with grant privileges 
Sql :: 2nd max salary query in sql 
Sql :: mysql add columns 
Sql :: where condition in mongodb 
Sql :: select only one row sql 
Sql :: delete from inner join sql 
Sql :: having count oracle two columns 
Sql :: distinct in sql server 
Sql :: oracle sql average 
Sql :: convert html to plain text in sql server 
Sql :: postgre query date 
Sql :: mysql sql select one day before 
Sql :: rand mysql 
Sql :: sql output select 
Sql :: mysql delete from where like 
Sql :: connecting to postgresql on windows amd ubuntu 20.04 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =