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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:29:39+00:00 2026-06-07T09:29:39+00:00

I have the following 2 tables tableA a (id, name, surname, program, date) tableB

  • 0

I have the following 2 tables
tableA a (id, name, surname, program, date)
tableB b (id, aid, name, surname, extracard)
with tableA.id = tableB.aid (1 to n relationship)

Sample data for tableA:
| ID | NAME  | SURNAME | PROGRAM |   DATE    |  EXPIRES  |
----------------------------------------------------------
| 1  | TOM   | JONES   | 1,2,3   | 12/8/2012 | 12/8/2013 |
| 2  | JAMIE | OLIVER  | 4,5,6   | 15/8/2012 | 15/8/2013 |

Sample data for tableB:
| ID | AID | NAME  | SURNAME | CARD |
-------------------------------------
| 1  |  1  | ANNE  | JONES   |  1   |
| 2  |  1  | JACK  | BOWER   |  0   |
| 3  |  2  | KATE  | PERRY   |  1   |
| 4  |  2  | JOHN  | DOE     |  0   |
| 5  |  2  | HARRY | POTTER  |  0   |

In the results, each member of tableB should have all values (program, date, expires, etc…) from tableA and display only the name, surname from tableB in the same column (coalesce??). Also, I need to use a between clause for a.id between (%id1 and %id2) and also a WHERE statement for selecting rows where tableB.card=1

| a.ID | NAME  | SURNAME | PROGRAM |   DATE    |  EXPIRES  |
------------------------------------------------------------
|  1   | TOM   | JONES   | 1,2,3   | 12/8/2012 | 12/8/2013 |
|  1   | ANNE  | JONES   | 1,2,3   | 12/8/2012 | 12/8/2013 |
|  2   | JAMIE | OLIVER  | 4,5,6   | 15/8/2012 | 15/8/2013 |
|  2   | KATE  | PERRY   | 4,5,6   | 15/8/2012 | 15/8/2013 |
  • 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-07T09:29:41+00:00Added an answer on June 7, 2026 at 9:29 am
     SELECT * FROM 
       ( (SELECT a.id ,a.name,a.surname,a.program,a.date,a.expires 
        from tableA a left outer join tableB b 
        on b.aid=a.id 
        where b.card=1 and (a.id between '1' and '2'))
        UNION ALL
        (SELECT a.id ,b.name,b.surname,a.program,a.date,a.expires 
        from tableA a left outer join tableB b 
        on b.aid=a.id 
        where b.card=1 and (a.id between '1' and '2'))) t
        ORDER BY id
    

    EDITED:
    Please refer to http://sqlfiddle.com/#!2/d8227/1

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

Sidebar

Related Questions

I have 3 tables with the following columns TableA Name Description ..... TableB Name
I have 2 tables in mysql: tableA and tableB tableA: idA tableB: idB, name
I have two tables: TableA ( ID [int, pk], Name [string]) and TableB (ID
I have the following table drop table names; create table names( name varchar(200), surname
I have the following two tables: Table1 ---------- ID Name 1 A 2 B
I have the following two tables in my mysql database. Table Name: groups id
I have the following tables: users +----------+----------+----------+ | id | name | dob |
I have the following tables in SQL Server 2005 ReceiptPoint: ID (PK), Name GasIndexLocation:
I have the following two tables: Customer { int Id int Name } Bills
I have two tables: Contact (id,name) Link (id, contact_id, source_id) I have the following

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.