SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Large query looking for differences in tables causing mysql to crash

    I have two tables with about 25k rows in each, and I am trying to find the differences between the two tables. The query is causing mysql to crash.

    This is the query:

    Code MySQL:
    SELECT *
    FROM data
    WHERE item NOT IN (
    SELECT item
    FROM data_backup)

    The item column is a varchar, but it contains a 13 digit number only. I am trying to find how many items from my inventory appear in one table over the over.

    Oh, I am using MySQL client version: 5.1.49

    Any ideas?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,327
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    SELECT data.*
      FROM data
    LEFT OUTER
      JOIN data_backup
        ON data_backup.item = data.item
     WHERE data_backup.item IS NULL
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help!

    Unfortunately, the query is still crashing both ssh and phpmyadmin when I attempt to run it.

    Any ideas on how I could better optimize it?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,327
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by bradical1379 View Post
    Any ideas on how I could better optimize it?
    indexes on the join columns

    could you please do a SHOW CREATE TABLE for both tables and i'll show you how
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Instead of
    Code:
    SELECT *
    do
    Code:
    SELECT id
    where "id" is the primary key column. If needed, you can retrieve the full rows after that, using the "id" results set.

    Or some other relevant column(s). "SELECT *" is generally a bad idea.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •