I want to use union all with manual value, not from another table. And the values are:
|cSatuan1|cSatuan2|nkonversi|
=============================
| LTR | PCS | 1 |
| PCS | LTR | 1 |
I've made the query with my own way, but it gets error. here is the query:
SELECT csatuan2, csatuan1, nkonversi
FROM ms_metriks union all select 'LTR','PCS','1','PCS','LTR','1'
Can you tell me what's wrong with my query, and what is the right query?
The SQL UNION operator Both tables must have the same number of columns. The columns must have the same data types in the same order as the first table.
The SQL UNION ALL operator is used to combine the result sets of 2 or more SELECT statements. It does not remove duplicate rows between the various SELECT statements (all rows are returned). Each SELECT statement within the UNION ALL must have the same number of fields in the result sets with similar data types.
Try this:
SELECT csatuan2,csatuan1,nkonversi FROM ms_metriks
UNION ALL SELECT 'LTR','PCS','1'
UNION ALL SELECT 'PCS','LTR','1'
Here is one way you can do it:
SELECT 'LTR' as csatuan1,'PCS' as csatuan2,'1' as nkonversi
UNION
SELECT 'PCS','LTR','1';
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