473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Group By with Order BY, or INSERT INTO (SELECT * GROUP BY)???

110 100+
I seem to have a few duplicates entries in a very large database.

My database has two identical tables. One is written to on a regular basis (every few seconds) and the other is used for queries, and updated from the write table on a daily basis.

I'm trying to get rid of duplicate entries for the queries, and I thought the most effective way to do this would be to run the query as
Expand|Select|Wrap|Line Numbers
  1.  
  2. INSERT INTO readtable (SELECT * FROM writetable GROUP BY column1, column2);
  3.  
I have also tried the same query, but listed each row instead of using a *.
The problem is this seems to be crashing my dev mysql server. Though SQL is not giving me an error.

My other option is to use the GROUP BY statement on the read table when a read request is made. But I thought building the read table without duplicates would be more efficient, and I have an ORDER BY statement in the read requests as well, and have read that mixing GROUP BY with ORDER BY is a no, no...

I have run the GROUP BY column1, column2 ORDER BY column 1, column6
and it seems to work ok.

Any thoughts on this?
Sep 9 '08 #1
2 8723
coolsti
310 100+
It might help if you explained the logic of your design to us.

Why are there duplicates in your write table? Are they needed (as for logging purposes) or are there duplicates because you do not know of a good way to not have duplicates when writing to the table?

What are your table structures (show the "show create table" output).

It may be possible and sufficiently efficient to create your "read" table as data is being added to your "write" table (assuming both are necessary according to my first comment above) instead of doing this on a daily batch basis.
Sep 10 '08 #2
pedalpete
110 100+
Hey Coolsti -
i was trying to keep things simple, that's why i didn't overload the previous message with info.

The data in the write table is added by a web indexer, and though it is pretty good at not duplicating data, for some reason a small percentage of duplicate data is getting through.

I tried creating a unique field of the duplicate data concat (bid, date, time), but for some reason that didn't work. meaning that it still seemed to be returning the same number of entries in the table.

The indexer is constantly running, and therefore there are many reads and writes to that table (reads to check for duplicate data, writes to only update if dups not found).

I tried running queries against one table originally, but the visitors queries were taking too long.

when I build the second table (read) for visitor queries, there was a huge performance jump.
my create tables looks like this
Expand|Select|Wrap|Line Numbers
  1.  
  2.  CREATE TABLE `update` (
  3.   `sid` int(40) NOT NULL auto_increment,
  4.   `bid` int(11) NOT NULL,
  5.   `ven` varchar(100) collate utf8_unicode_ci NOT NULL,
  6.   `address` varchar(100) collate utf8_unicode_ci NOT NULL,
  7.   `city` varchar(100) collate utf8_unicode_ci NOT NULL,
  8.   `state` varchar(100) collate utf8_unicode_ci NOT NULL,
  9.   `zip` varchar(50) collate utf8_unicode_ci NOT NULL,
  10.   `lat` float NOT NULL,
  11.   `long` float NOT NULL,
  12.   `date` date NOT NULL,
  13.   `time` time NOT NULL,
  14.   `accuracy` tinyint(2) NOT NULL default '0',
  15.   `geo` tinyint(1) NOT NULL default '0',
  16.   PRIMARY KEY  (`sid`),
  17.   KEY `getshows_idx` (`lat`,`long`,`date`),
  18.   KEY `location_idx` (`address`,`city`,`state`)
  19. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
  20.  
the read table is the same, except for the table name.


It might help if you explained the logic of your design to us.

Why are there duplicates in your write table? Are they needed (as for logging purposes) or are there duplicates because you do not know of a good way to not have duplicates when writing to the table?

What are your table structures (show the "show create table" output).

It may be possible and sufficiently efficient to create your "read" table as data is being added to your "write" table (assuming both are necessary according to my first comment above) instead of doing this on a daily batch basis.
Sep 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ask Bjørn Hansen | last post by:
Hi, I am trying to control which element gets picked when I do a group by, but I can't figure out how to do it. First some example data: CREATE TABLE t ( id int not null primary key...
3
by: Rich Protzel | last post by:
Hello, So my table contains say 100,000 records, and I need to group the categories in fld1 by the highest count of subcategories. Say fld1 contains categories A, B, C, D, E. All of these...
4
by: Chad Richardson | last post by:
I've always been mistified why you can't use a column alias in the group by clause (i.e. you have to re-iterate the entire expression in the group by clause after having already done it once in the...
9
by: cyrus.kapadia | last post by:
Let's say I have the following table: entry product quality 1 A 80 2 A 70 3 A 80 4 B 60 5 B 90 6 ...
6
by: throat.wobbler.mangrove | last post by:
Hi, I was hoping someone may be able to help me with a tricky T-SQL problem. I need to come up with a SELECT statement that does basically the following: Select RCRD_REFNO, MAX(MODIF_DTTM)...
5
by: Mike Nolan | last post by:
I notice that 7.4 doesn't do default ordering on a 'group by', so you have to throw in an 'order by' clause to get the output in ascending group order. Is this something that most RDB's have...
10
by: Rudolf Bargholz | last post by:
Perhaps some kind soul could help me out with an SQL I have been trying all day to get to work, where one colum is just not summing up the way I want it to. I have the following data GRP_SEQ ...
1
by: Rantoun | last post by:
I know what I am asking for is pretty hard, but still maybe there is someone out there who is able to solve my problem! I have a table that look like this CREATE TABLE VEHICLETRIPS ( VID...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.