Avatar of dsrnu
dsrnu
 asked on

Query Help - joining tables/union

Hi everyone,

I was wondering if there was a way to join two tables together where:

- pull all information from table 1
- pull added information from table 2, if it exists (combine like table1.id = table2.id)

I tried using join (left, right, inner, outer, etc.) but no luck.
Table: seller

----------------
- id - user_id -
----------------
- 1  -   50    -
- 2  -   53    -
- 3  -   67    -
----------------

Table: user

-------------------------------------
- id - username - email             -
-------------------------------------
- 1  - jdoe     - jdoe@gmail.com    -

....

- 50 - suprman  - suprman@gmail.com -
- 51 - wndrwmn  - wndrwm@gmail.com  -
-------------------------------------

Desired Output:

Pull all data from "user" table and include "seller" data, if user.id = user_id exists.

Open in new window

PHPMySQL Server

Avatar of undefined
Last Comment
dsrnu

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
rubene

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
gplana

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
dsrnu

ASKER
rubene:

the second query was what i was looking for =)

when i get the results, how would i rename s.user_id to IS_SELLER so it's more meaningful?
dsrnu

ASKER
SELECT u.id AS user_id, u.username, s.user_id AS is_seller FROM
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes