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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:00:47+00:00 2026-06-13T17:00:47+00:00

I have two tables: Table A: | id | type | name | 1

  • 0

I have two tables:

Table A:

| id | type   | name
| 1  | Person | Fred
| 2  | Animal | Rover
| 3  | Animal | Snowball
| 4  | Person | Mary

Table B:

| id | city
| 1  | NYC
| 4  | Charlotte

What I want:

| id | type   | name     | city
| 1  | Person | Fred     | NYC
| 2  | Animal | Rover    | NULL
| 3  | Animal | Snowball | NULL
| 4  | Person | Mary     | Charlotte

In other words, Table A is a table of People and Animals. Table B is a table of the cities people live in. I would like to (In a single query, if possible) get every result from Table A and, if it’s a person, get that person’s city in Table B. Is that possible in a single query? If not, what is the fastest way?

I’ve tried to do a simple join (e.g. “SELECT * FROM tableA,tableB WHERE tableA.id==tableB.id”), but doing that only gets the results of the people and not the animals.

thx!

  • 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-13T17:00:48+00:00Added an answer on June 13, 2026 at 5:00 pm

    Use LEFT JOIN on this

    SELECT  a.*, b.city
    FROM    tableA a
            LEFT JOIN tableB  b
                ON a.ID = b.ID
    

    SQLFiddle Demo

    and assuming that only person has records on tableB

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

Sidebar

Related Questions

I have two tables: <h3>JVM Garbage Collector</h3> <table style=width:100% border=1> <tr><th>Name</th><th>Description</th><th>Type</th><th>Key</th></tr> <tr> <td style=width:25%>PS
I have two tables table COMMUNITY id, name, etc. table PROPERTY id, community_id, type,
Assume I have two tables, Student Test Id Name TestId Type StudentId -- ----
I have two tables Table public.tags_to_entities Column | Type | Modifiers --------+---------+----------- tid |
I have this two tables: Table A ID TYPE SDATE EDATE RATING 1 M
I am using luasql. I have two tables of this type: IPINFO CREATE TABLE
I have two tables: a Files table, which includes the file type, and a
Into I have two tables profile and name , the profile table contains some
Say I have two tables: object id name object_event id object_id type date I
I have two tables Table A type_uid, allowed_type_uid 9,1 9,2 9,4 1,1 1,2 24,1

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.