Jump to content


Checking Two Tables For Matching Records

  • Please log in to reply
1 reply to this topic

#1 c_pattle


    Advanced Member

  • Members
  • PipPipPip
  • 295 posts

Posted 13 December 2012 - 03:55 PM

I was just wondering if anyone knows what the most efficient way of checking to see if two tables contain matching records.

So for example I have a table called 'orders' which have a primary key of order_id.

Then I have a table called 'order_comments' which also has a field called order_id and I want to run a query that will check which orders don't have entries in order_comments.

Thanks for any help

#2 Barand


    Sen . ( ile || sei )

  • Moderators
  • 16,255 posts
  • LocationCheshire, UK

Posted 13 December 2012 - 05:28 PM

SELECT o.order_id
FROM orders o
LEFT JOIN order_comments c USING (order_id)
WHERE c.order_id IS NULL

Edited by Barand, 13 December 2012 - 05:28 PM.

Posted Image

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users