Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7613833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:15:00+00:00 2026-05-31T02:15:00+00:00

I’m looking for a mysql query (using php) to go through each table one

  • 0

I’m looking for a mysql query (using php) to go through each table one at a time and only display results that are different than those in cross_check.lastmod

t_one

guid | name | lastmod
 1   |  Joe | 2012-01-01 01:00:00
 2   |  Tom | 2012-01-02 01:00:00
 3   |  Sue | 2012-03-01 02:00:00

t_two

guid | pet  | lastmod
 4   | cat  | 2012-01-01 01:00:00
 5   | dog  | 2012-01-02 01:00:00
 6   | fish | 2012-03-01 02:00:00

t_three

guid | fruit   | lastmod
 7   |  orange | 2012-01-01 01:00:00
 8   |  pear   | 2012-01-02 01:00:00
 9   |  grape  | 2012-03-01 02:00:00

cross_check

guid | lastmod
   1 |  2012-01-01 01:00:00
   2 |  2012-01-02 01:00:00
   3 |  2012-01-01 02:00:00
   4 |  2012-01-01 01:00:00
   5 |  2012-01-02 01:00:00
   6 |  2012-01-01 02:00:00
   7 |  2012-01-01 01:00:00
   8 |  2012-01-02 01:00:00
   9 |  2012-01-01 02:00:00

The query results would be:

t_one => 3 | Sue   | 2012-03-01 02:00:00
t_two => 6 | fish  | 2012-03-01 02:00:00
t_three => 9 | grape | 2012-03-01 02:00:00

My code so far (needs the table cross reference)

$tables = array('t_one', 't_two', 't_three');

  foreach ($tables AS $table) {

    $query = sprintf("SELECT * FROM '%s'",
    mysql_real_escape_string($table));

    $result = mysql_query($query);

  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:15:02+00:00Added an answer on May 31, 2026 at 2:15 am

    Just JOIN in the cross_check table.

    SELECT t_one.*
    FROM t_one
    JOIN cross_check ON t_one.guid=cross_check.guid
    WHERE t_one.lastmod != cross_check.lastmod
    

    Still one query per table, though (you can fart around with unions but that doesn’t reduce the core number of queries).

    If you wanted to combine them into one, you could use UNIONs:

    [query for t_one]
     UNION
    [query for t_two]
     UNION
    [query for t_three]
    

    I feel like this isn’t all that more efficient than doing three different queries (a gut feel though, unsubstantiated claim).

    You could also do (although this only works if there’s no crossover between the t_* guids; if there is t_one will be favoured, then t_two):

    SELECT COALESCE(t_one.guid,t_two.guid,t_three.guid) AS guid
    FROM cross_check
    LEFT JOIN t_one ON t_one.guid=cross_check.guid 
    LEFT JOIN t_two ON t_two.guid=cross_check.guid
    LEFT JOIN t_three ON t_three.guid=cross_check.guid
    WHERE (t_one.lastmod IS NOT NULL AND t_one.lastmod != cross_check.lastmod)
       OR (t_two.lastmod IS NOT NULL AND t_two.lastmod != cross_check.lastmod)
       OR (t_three.lastmod IS NOT NULL AND t_three.lastmod != cross_check.lastmod)
    

    You could also put COALESCE(t_one.name, t_two.pet, t_three.fruit) AS label if you wanted to grab the labels as opposed to the ids.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I have a jquery bug and I've been looking for hours now, I can't
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.