1

I have two tables in my database like this:

 Table-1                          Table-2

 id Name                          id  Name 
 1  A                              1  D-a
 2  B                              2  D-b
 3  C                              3  D-c 
 4  D

I want a query which gives me output such as

A B C D-a D-b D-c

i.e. check if there is entry of D in Table-1 if there is then select all entries of Table-2 and remove D from output

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    this one `check if there is entry of D in Table-1 if there is then select all entries of Table-2 and remove D from output` is not clear. – A_Sk Mar 23 '15 at 05:33
  • 1
    give the column name in your result to understand your output and we make query accordingly – Ajay2707 Mar 23 '15 at 06:00

1 Answers1

0

I think this is not the best answer to your question, but it can help you:

Select Distinct Table1.name
From Table1, Table2
WHERE Not Table2.name Like Table1.name+'%'
UNION All
Select Distinct Table2.name
From Table1, Table2
WHERE Table2.name Like Table1.name+'%'

Now you have your results in a column.
If you want to have them in a row follow this question:
Concatenate many rows into a single text string

Community
  • 1
  • 1
shA.t
  • 16,580
  • 5
  • 54
  • 111