SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is a sub query necessary for this ?

    Hi All,

    Is there a way to make this query more efficient?

    Perhaps using group by ?

    I am trying to find photos where no photo has been designate as main.

    SELECT property.property_id
    FROM property
    WHERE property.property_id NOT
    IN (

    SELECT property.property_id
    FROM property, property_photo
    WHERE property.property_id = property_photo.property_id
    AND property_photo_main = '1'
    )

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,254
    Mentioned
    113 Post(s)
    Tagged
    1 Thread(s)
    you can try this

    Code:
    SELECT p.property_id
              , pp.property_id
       FROM property p
        LEFT JOIN property_photo pp ON p.property_id = pp.property_id 
                                                 AND pp.property_photo_main = '1'
     WHERE pp.property_id IS NULL
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style


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
  •