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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:04:43+00:00 2026-05-30T00:04:43+00:00

OK this is bit complicated because my tables are not referenced or combined or

  • 0

OK this is bit complicated because my tables are not referenced or combined or to be matched with each other so I cant use JOIN’s. I am building a search form that would simply match search keyword in multiple tables.

The issue I have is that I have to generate news item link depending from which table the result came but I cant find a hook. MySql union works perfect except that I cant check if data is from table a or table b.

here is short version 
SELECT  i.title,i.category FROM table_a  WHERE REGEXP 'news'
UNION 
SELECT i.title,i.category FROM table_b WHERE REGEXP 'news'

now , my table A has 36 rows and table B has 34 , one more difference is that table A has row name extra_field which I wanted to check and based on that switch my link.

php switch after query could be something like

foreach($rows as $row) :
if($row->extra_field):
$link = 'index.php?".$row->category.$row->title".html'
else:
$link = 'index.php?".$row->title".html'
endif;
endforeach;

So is there a way to check in my UNION sql if that row exists? I know how to check if row exists but how to do that in UNION?

Please help. Thank you!

  • 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-30T00:04:44+00:00Added an answer on May 30, 2026 at 12:04 am

    Using your short version as an example, you could add an extra column to the query:

    SELECT  i.title,i.category,'a' as source FROM table_a  WHERE REGEXP 'news'
    UNION 
    SELECT i.title,i.category, 'b' as source FROM table_b WHERE REGEXP 'news'
    

    Then in your code you could check the ‘source’ column.

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

Sidebar

Related Questions

This is a bit of a complicated question because I don't really know where
I'm not the best with multi-threading, and this is a bit complicated, so hopefully
So this problem is a little bit complicated to understand what I'm trying to
Okay, this is a bit complicated so please bear with me. :) We have
This is little bit complicated SQL query wich needs to fetch all the views
This one is bit complicated than sinmple range in mysql , my field data
This is a bit complicated but here goes. I have a Rails app that
This bit of code is taking almost a half second to execute. Could somebody
This bit of code comes with new classes that are subclasses of UITableViewController... -
To this bit of code I pass the string kellogs special k and 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.