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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:22:09+00:00 2026-05-28T17:22:09+00:00

I have a table1 (records 3), and table2 (records 3). Where i have field

  • 0

I have a table1 (records 3), and table2 (records 3).

  • Where i have field name in both.
  • Now i want to make a result from those two table
  • which will show me both table records and take only one if there is duplicate.
  • from that result i will do main query using like or or other logical statements
  • So my expected output records will contain 5 rows not 6 rows. How do i do that?

Example:

table1:                       table2:

+-------------------------+   +--------------------------------+
| Name            | ID        | Name            | ID
+--------------------------   +---------------------------------
| A               |  1        | 1 December Name | 4
| B               |  2        | D               | 5
| 1 December Name |  3        | E               | 6


My Expected output is following which works, but does not work when i use WHERE
like to only get '1 December Name':

+-----------------------------------------------------+
| Name               | ID                
+-----------------------------------------------------
| A                  | 1 table1
| B                  | 2 table1
| 1 December Name    | 3 table2 or table1 (no unique)
| D                  | 4 table2
| E                  | 5 table2

I tried this:

SELECT * FROM 
(
    ( 
     SELECT name AS name FROM table1 
    ) 
UNION 
    ( 
     SELECT anothername AS name FROM table2 
    )
) as t
WHERE name like '%1 December Name%'
    limit 1,10

Output: Your SQL query has been executed successfully ( Query took 0.2798 sec )

Problem: The following query has no error but it does not find that record which contain ‘1 December Name’

Follow up: works i know now which ID it used

SELECT NAME, ID, STATUS FROM 
(
 (
   SELECT NAME AS name       , id, CONCAT('table1')   AS STATUS FROM table1
 )
UNION ALL
 (
   SELECT ANOTHERNAME AS name, id, CONCAT( 'table2' ) AS STATUS FROM table2
 )
) AS t

WHERE 

 t.NAME LIKE '%1 December Name%'

LIMIT 1 , 10;
  • 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-28T17:22:10+00:00Added an answer on May 28, 2026 at 5:22 pm

    You can get something similar to what you want:

    select name, group_concat(id) from
    (select name, 'table1' as id from table1
    union all 
    select name, 'table2' from table2) x
    group by name
    

    Output would be:

    +------------------------------------+
    | Name               | ID                
    --------------------------------------
    | A                  | table1
    | B                  | table1
    | 1 December Name    | table1,table2
    | D                  | table2
    | E                  | table2
    

    UNION ALL is the right choice (not UNION), because it does not remove duplicates, and preserves row order

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

Sidebar

Related Questions

i have a table with about 200,000 records. i want to add a field
I have table a joining table b, I only want the records from table
I have two tables with exactly the same fields. Table A contains 7160 records
I have records in table1, if the records exist, it must copy into table2.
I have two tables; table1, table2, however table1 only has 1 record and table2
i have two table. Records and Villas Records table : ID, VID (Villa ID),
I have a table similar to the following id | name | address both
I have two tables. Each one is populated with about 50K records. Both have
I have two tables here both contain like lots of records in the tens
I have the correlated subquery below. Each id (147,148,149) in table1 has many records

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.