SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Self Join

  1. #1
    SitePoint Member
    Join Date
    May 2003
    Location
    nowhere
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Self Join

    I use the folowing for a self join in MySQL
    SELECT * FROM post_table t1
    INNER JOIN post_table t2 ON (t1.post=t2.post)
    INNER JOIN post_table t3 ON (t2.post=t3.post)
    WHERE t1.index BETWEEN 294 AND 1318
    AND t2.index BETWEEN 2210 AND 3379
    AND t3.index BETWEEN 30122 AND 30237

    This runs very slow and my host doesnt support sub querys. Any ideas on how to make this more efficient

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,022
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    indexes?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Santos L Halper Zenith's Avatar
    Join Date
    May 2002
    Location
    Finland
    Posts
    641
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First mistake is: SELECT *

    You should never ever make an SQL clause that way. Even though you need all fields you'd name them.

    If you have heavy join pick only columns you need, that'll make it a lot quicker.


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
  •