I have two table
table one is scheduletime
id | edition | time |
1 | 1 | 9:23am |
2 | 2 | 10:23am|
table two is actualtime
id | edition | time |
1 | 1 | 10:23am |
2 | 2 | 11:23am |
I want to result as
Caption | Edition | Time |
Scheduleed | 1 | 9:23am |
actual | 1 | 10:23am |
Scheduleed | 2 | 10:23am |
actual | 2 | 11:23am |
How can do this in MySQL ?
For this, you can use group_concat () with aggregate function. Let us first create a table − Here is the query to concatenate 2 values from the same column with different conditions −
You can easily link or “join” two or tables in MySQL with the JOIN clause that combines the rows from several tables based on a column that is common to all the tables.
Self joins with hierarchical data and multiple relationships between two tables are just two of the situations for which you need to join the same table twice. There are others; generally, they involve adding one or more columns to a result set from the same table in the same column.
There are four easy ways to join two or more tables: Inner Join. Left Join. Right Join. Union. Cross Join or Cartesian Product. Self Join. FULL OUTER JOIN.
SELECT Caption, Edition, Time
FROM
(
SELECT 'Scheduled' Caption, Edition, time
FROM scheduleTime
UNION ALL
SELECT 'Actual' Caption, Edition, time
FROM scheduleTime
) subquery
ORDER BY Edition, FIELD(Caption, 'Scheduled', 'Actual')
FIELD()
, just plain ORDER BY...DESC
)OUTPUT
╔═══════════╦═════════╦═════════╗
║ CAPTION ║ EDITION ║ TIME ║
╠═══════════╬═════════╬═════════╣
║ Scheduled ║ 1 ║ 9:23am ║
║ Actual ║ 1 ║ 9:23am ║
║ Scheduled ║ 2 ║ 10:23am ║
║ Actual ║ 2 ║ 10:23am ║
╚═══════════╩═════════╩═════════╝
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