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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:37:19+00:00 2026-05-25T03:37:19+00:00

I want a query to grab results from 2 different tables where a specific

  • 0

I want a query to grab results from 2 different tables where a specific user has added the row. So my 2 tables look like this:

addresses

  • id
  • address
  • user_id

emails

  • id
  • email
  • user_id

So, I want to pull the content from both tables where the user_id row equals 1. For context, imagine each user can add multiple addresses and emails to the site and I want to grab them all to display on their profile pages.

So I tried this:

SELECT *  
  FROM addresses
  JOIN emails USING (user_id) 
 WHERE user_id = '1'

However this doesn’t work – It either returns 2 of each row from the first table, or nothing at all.
I also tried this:

SELECT * 
  FROM addresses, 
       emails 
 WHERE user_id = '1'

But this also returns nothing.

  • 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-25T03:37:20+00:00Added an answer on May 25, 2026 at 3:37 am

    Simple Union Version:

    Select user_id, address as details from addresses
    where user_ID = 1
    UNION 
    Select user_id, email as details from emails
    where user_ID = 1
    

    Here is some quick reading on union:
    http://www.tizag.com/sqlTutorial/sqlunion.php

    From Input

    table1:                        table2
    
    id  user_id  address           id    user_id   email
    ----------------------         ----------------------
    1   1        Add1              1       1       Email1
    2   1        Add2              2       1       Email2
    3   2        Add3              3       2       Email3
    4   2        Add4              4       3       Email4
    

    The results will be

    user_id     details
    -----------------------
    1           Add1
    1           Add2
    1           Email1
    1           Email2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So in this program I'm writing, I actually grab a SQL query from the
I'm accepting dates from a wicket form - now I want query my DAO
I want to query a number of different databases mainly Oracle and Informix. Can
I want to query Active Directory from Windows PE 2.0, which is not supported
I want a query that returns a list of all the (user) stored procedures
I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using
We want the query result should be assigned with two results based on some
I want to query a column that has spaces in its name. The shell
I want to grab a user's uploads (ie: BBC) and limit the output to
I want to make a query so that I can grab only Locations that

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.