473,785 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

110 New Member
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 8744
coolsti
310 Contributor
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 New Member
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
1947
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 auto_increment, group_id int not null, level int not null); INSERT INTO t VALUES (1,1,2);
3
4618
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 categories contain subcategories AA, AB, AC, AD,...AJ, BA, BB...BJ, CA, CB, CC...CJ, etc in fld2. I am counting how many subcategories are listed for each category. Like
4
28825
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 select statement). I'm mostly a SQL hobbiest, so it's possible that I am not doing this in the most efficient manner. Anyone care to comment on this with relation to the following example (is there a way to acheive this without re-stating the...
9
3309
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 C 80 7 D 80
6
42330
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) as MODIF_DTTM from ..tblPersonInfo group by RCRD_REFNO
5
3232
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 historically done (including PG prior to 7.4) but isn't really part of the SQL standard? On a mostly unrelated topic, does the SQL standard indicate whether NULL should sort to the front or the back? Is there a way to force it to one or the other...
10
10003
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 ITEM_SEQ NR_ITEMS PERSONS_SEQ 1 A 2 aa 1 A 2 bb
1
3985
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 NUMBER(10) NOT NULL, VECHIELID VARCHAR2(10) NOT NULL, DEVICEDATE DATE NOT NULL, TRIPID NUMBER(10) NOT NULL, COMMUNITY VARCHAR2(10) NOT NULL
5
13381
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 http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.