Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

combining two varchar fields in same SELECT statement without merging values

Tags:

mysql

The SQL query in my PHP file is

SELECT start_time,end_time FROM data;

This returns the two varchar fields in two different columns. Now i wish to combine these. So I tried

Select start_time+' '+end_time as time from data;

This returns some numeric value. So I tried:

Select cast(start_time+' '+end_time) as time from data;

If the data in my table is start_time = 8:00 a.m end_time = 9:30 a.m

how can I display 8:00 a.m - 9:30 a.m.

like image 474
BountyHunter Avatar asked Sep 17 '25 19:09

BountyHunter


2 Answers

Select CONCAT(start_time, ' - ', end_time) as time FROM data
like image 181
Roman Marusyk Avatar answered Sep 19 '25 21:09

Roman Marusyk


You're looking for CONCAT().

SELECT CONCAT(start_time, ' ', end_time) AS time FROM data;
like image 32
Rocket Hazmat Avatar answered Sep 19 '25 23:09

Rocket Hazmat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!