i want to query two tables then give the result in one column eg
table1
id   name  town 
23   john  nyc
34   mark  ATl
44   ali   Dubs
table2
cno reg
45  kln
47  dsgd
28  wer
the output i expect is
newcolumn
   23
   34
   44
   45
   47
   28
                In SQL, to fetch data from multiple tables, the join operator is used. The join operator adds or removes rows in the virtual table that is used by SQL server to process data before the other steps of the query consume the data.
By replacing the existing column using REPLACE() function with CONCAT() function.
The join is done by the JOIN operator. In the FROM clause, the name of the first table ( product ) is followed by a JOIN keyword then by the name of the second table ( category ). This is then followed by the keyword ON and by the condition for joining the rows from the different tables.
You need to use MySQL UNION.
SELECT id FROM table 1
UNION 
SELECT cno AS id FROM table2
In UNION, you can combine results from two or more database tables.
But, it needs that the selected columns should be similar.
For example, if you are fetching 5 fields from one SQL and 6 fields from another SQL.
And making UNION of these two queries, it will not work.
Above SQL works because, you are selecting one column each from SQLs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With