Solved

merge data from diferent tables without relations

Posted on 2016-08-24
3
49 Views
Last Modified: 2016-08-25
I hope you can help me with this

I have this two querys
query 1
select field1 from table1 where field1 = 'a'

Open in new window


query 2
select field2 from table where field2 = 'a'

Open in new window


I need to present to my user field1 and field2 as a one table

I was trying to use a union
select field1 from table1 where field1 = 'a'
union all
select field1 from table1 where field1 = 'a'

Open in new window


but mysql show me the result in a single column and I need it in two, for example:
-------------------------------------------------------------
|   field 1                       |       field 2                |
|-----------------------------------------------------------|
|  results of field 1      |  results of field2     |
-------------------------------------------------------------

is it possible to do it like that???
0
Comment
Question by:altariamx2003
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
WalkaboutTigger earned 500 total points
ID: 41769606
Select Query1.someCommonField, Query1.field1, Query2.field2
From
(
Select field1, someCommonfield1 as "Common" from table1 where field1 ='a'
) as Query1
inner join
(
Select field2, someCommonField2 as "Common" from table2 where field2='a'
) as Query2
On Query1.Common = Query2.Common
Order By Query1.field1

Open in new window

Realise that the SQL server NEEDS to know how the information from the two fields relate to one another in order to match up the two values.
You, as a human being and familiar with the data, can match the two up.  How are you doing that?  How can you express it in clear language?
Once you can do that, you can fix the query above to meet your needs, even if the relationship is complex.
0
 

Author Comment

by:altariamx2003
ID: 41770953
thx I found the solution by myself, instead of union i use cross join
0
 

Author Closing Comment

by:altariamx2003
ID: 41770955
Thx anyway for your time, but I found the solution bymyself
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question