0

I have two tables in my database. "A" table is the main table that stores user primary information and other table "B" stores if user wants to add some additional address onto their profile.

Structure of both tables(has common columns with exact same names) is as per below picture except some diff columns that are not shown in this pic

enter image description here

Now i want to display Address stored in Table A as well as in Table B

I used below queries but all these return only values from Table B

Query 1 :

Select t1.(star),t2.(star) from `b` t2 , `a` t1 WHERE t1.emailbc = ?; 

Query 2 :

Select t1.(star),t2.(star) from `a` t1 
INNER JOIN `b` t2 ON (a.emailbc=b.emailbc) 
WHERE t1.emailbc = ?

I also tried NATURAL Join but that does not work either. Please let me know solution.

2
  • use t1.(star) as star1 ,t2.(star) as star2 Commented May 20, 2015 at 18:14
  • Can you show some sample data and how you want your results to be displayed? Commented May 20, 2015 at 18:27

2 Answers 2

1

If you want to display all addresses in one column, but coming from both tables, you need to use a UNION. Try this:

SELECT *
FROM table1
WHERE emailbc = ?
UNION
SELECT *
FROM table2
WHERE emailbc = ?
Sign up to request clarification or add additional context in comments.

4 Comments

@akr yes, but the way to OP explained it doesn't sound like a JOIN to me.
i think this served the purpose... but how about JOINS
JOINS will display the data adjacent to each other. If you want all addresses in one single column, you are looking for a UNION.
i do not want all address in single columns.. let me show you how i want addresses to be.. Here is the link to image... postimg.org/image/9in93jbd1 .. i want all address to be displayed like this which i am getting with UNION.. but JOINS will be much beeter
0

Change your join query to the following.

Select t1.*,t2.* from `a` t1 
INNER JOIN `b` t2 ON (t1.emailbc=t2.emailbc) 
WHERE t1.emailbc = ?

3 Comments

I can't spot the difference between your query and theirs?
@McAdam331, the query had not used the alias t1 and t2 in the on part of the query.
@akr .. this does not chnage anythng

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.