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

The Archive Base Latest Questions

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

I asked a similar question yesterday but still having a slight problem on output.

  • 0

I asked a similar question yesterday but still having a slight problem on output. Unions only always combines it into one column and there is no relation to do a join. Here is what I want. I don’t want to combine.

SELECT prd_id FROM products WHERE title LIKE %$var%;

AND

SELECT lst_id FROM lists WHERE title LIKE %$var%;

I want both of these in one query and output the results it finds into 2 columns IF there is a result for either one. I also would like to use a LIMIT at the end too.

So for example if both tables have an item that matches the title then it will return something like. Note the values will be whatever it matched in each table. The point is just to be in 2 columns instead of one like Unions output.

+-----------------+  
| prd_id | lst_id |   
+-----------------+   
|  value | value  |   
+-----------------+   

I get close but just can’t it exactly.

To make it clear, the PHP print_r output should be like this. This example is if 2 items are matched in the list table only

Array ( [0] => Array ( [lst_id] => 100007 ) [1] => Array ( [lst_id] => 100008 ))

This example is if 1 item from each table is matched

Array ( [0] => Array ( [prd_id] => 100006 ) [1] => Array ( [lst_id] => 100008 ))

There can be any number of matches from either of the tables.

  • 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:41:04+00:00Added an answer on May 31, 2026 at 2:41 am

    The simplest answer would be to union the results into different column, like so:

    SELECT prd_id, 0 lst_id FROM products WHERE title LIKE %$var%
    UNION ALL
    SELECT 0 prd_id, lst_id FROM lists WHERE title LIKE %$var%;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked a similar question yesterday, but now I have a slight twist. Since
I asked a similar question yesterday, but have acquired a really odd problem since
I asked a similar question yesterday, but recognize that i need to rephase it
I asked a similar question like this yesterday but after waiting for ever I
I asked yersterday this question. Now I am having problem with the similar XML
I asked a similar question yesterday that was specific to a technology, but now
Its similar question that I asked yesterday here with a slight modification. Here are
I asked a similar question yesterday but I included some code that basically took
This question is about a similar javascript scope problem that I asked yesterday .
This is similar to a question I asked yesterday but more specific to the

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.