我想建立一个新桌,其特性是老板,没有重复。 我想做的是:
CREATE TABLE New_Users LIKE Old_Users,
AS
(SELECT * FROM Old_Users GROUP BY ID) ;
但是,上述情况并不可行。 任何人都能够修改它,使之发挥作用?
我想建立一个新桌,其特性是老板,没有重复。 我想做的是:
CREATE TABLE New_Users LIKE Old_Users,
AS
(SELECT * FROM Old_Users GROUP BY ID) ;
但是,上述情况并不可行。 任何人都能够修改它,使之发挥作用?
你的尝试就是这样坏的。 页: 1
http://dev.mysql.com/doc/refman/5.1/en/create-table.html” 它说:
Use LIKE to create an empty table based on the definition of another table, including any column attributes and indexes defined in the original table.
您:
CREATE TABLE New_Users LIKE Old_Users;
之后插入
INSERT INTO New_Users SELECT * FROM Old_Users GROUP BY ID;
但你不能在一次发言中这样做。
http://dev.mysql.com/doc/refman/5.0/en/create-table-select.html
什么是:
Create Table New_Users Select * from Old_Users Where 1=2;
并且,如果这种工作不奏效,则在创造后仅选择一行和一行:
Create table New_Users select * from Old_Users Limit 1;
Truncate Table New_Users;
EDIT:
I noticed your comment below about needing indexes, etc. Try:
show create table old_users;
#copy the output ddl statement into a text editor and change the table name to new_users
#run the new query
insert into new_users(id,name...) select id,name,... form old_users group by id;
这样做。 似乎你正在这样做,以清除重复? 在此情况下,你可能希望就补贴问题制定独特的指数。 如果它是一个主要的关键,就应当做到。 你们也可以:
#make primary key
alter table new_users add primary key (id);
#make unique
create unique index idx_new_users_id_uniq on new_users (id);
For MySQL, you can do it like this:
CREATE TABLE New_Users SELECT * FROM Old_Users group by ID;
CREATE TABLE new_table LIKE age_table;
或u 可以使用
CREATE TABLE new_table as SELECT * FROM old_table WHERE 1 GROUP BY [column to remove duplicates by];
您可使用以下表格,并在表格中插入不同的价值观:
Select Distinct Column1, Column2, Column3 into New_Users from Old_Users
I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...
<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...
我把我的用心从使用QQL转向MySQL。 它与凯科特合作,现在不工作,因为我已经改变,使用MySQL。 这里的错误信息是:
We have a restaurant table that has lat-long data for each row. We need to write a query that performs a search to find all restaurants within the provided radius e.g. 1 mile, 5 miles etc. We have ...
Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...
Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...
What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...
My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...