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 8549465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:43:05+00:00 2026-06-11T13:43:05+00:00

I have a db with 8 tables which intend to search for an id

  • 0

I have a db with 8 tables which intend to search for an id number by joining them but i would like to retrieve the name of the table to use in a php along the lines of…

if($tablename == 'accounts'){
     echo 'value found in accounts';
}

What would the mysql query be?

(I don’t need help with the joining etc, just the bit that would get the table name and how to store it in $tablename)

Thanks

  • 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-06-11T13:43:06+00:00Added an answer on June 11, 2026 at 1:43 pm

    How can you search for data in a table if you don’t know the table name in the first place?

    So I suppose that you already know the table names, and don’t need things like SHOW TABLES; that you have e.g. a WHERE of the form

    WHERE (table1.field LIKE '%search%' OR table2.field2 LIKE '%search%' OR ...)
    

    and once retrieved a row, you know it matches, but you don’t know where the match did occur. And running eight straight queries instead of one JOINed isn’t an option.

    If this is the case, you’ll have to supplement your SELECTed fields with a flag to tell you what you need:

    SELECT ..., CASE
        WHEN accounts.field1 LIKE '%search%' THEN 'accounts'
        WHEN customers.name LIKE '%search%' THEN 'customers'
        ...
        END AS wtf FROM <rest of your query>
    

    Then in PHP when retrieving the row, you will just use the field:

    print "Value found in {$row['wtf']}";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables which looks something like this Table Queue int ID; string
I have many table creation scripts (sql files), which I would like to run,
I have 2 tables which I want to query from. The first table (lets
I have two tables which have some transactional stuff stored in them. There will
I use Hibernate with Java. I have two tables which are associated with foreign
I have a card-game application which makes use of Single Table Inheritance. I have
The Scenario: I have an ASP.Net webpage which I intend to use for letting
I have 3 tables which need to be linked in an SQL statement (I'm
I have two tables which are used to store details of different types of
I have two tables which I want to join together using a left outer

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.