Link to home
Create AccountLog in
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

ASKER CERTIFIED SOLUTION
Avatar of rubene
rubene
Flag of Netherlands image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Avatar of gplana
gplana
Flag of Spain image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of dsrnu
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?
Avatar of dsrnu

ASKER

SELECT u.id AS user_id, u.username, s.user_id AS is_seller FROM