0

i have two rows as show in below image.i want to get it as a single column based on aday(TUE) in the table,please any help me how to workout this. thanks in advance

enter image description here enter image description here

8
  • you can use LIMIT 1 with mysql query Commented May 27, 2014 at 11:26
  • Post your sql please. Also, are you looking for a single column or single row? Single row is LIMIT 1 and column is just SELECT aday FROM ... Commented May 27, 2014 at 11:29
  • Also, how do you decide which row you want? Commented May 27, 2014 at 11:30
  • Where does your question relate to Java? Do you want to just merge those 2 rows into a single row or do you want to do some magic in SQL (i.e. concatenation) to return a single column. Please edit your question to be more precise. Commented May 27, 2014 at 11:30
  • what is your expectation? explain output with above example. Commented May 27, 2014 at 11:43

2 Answers 2

2

You can't as that would give variable numbers of columns for the rows returned.

You can do a fiddle with GROUP_CONCAT:-

SELECT doctorname, aday, GROUP_CONCAT(CONCAT_WS('~', availfrom, availupto) SEPARATOR '#') avail_time_slots
FROM sometable
GROUP BY doctname, aday

Then in code you would need to split up the avail_time_slots

Sign up to request clarification or add additional context in comments.

2 Comments

thank its working fine,now i am trying to split avail_time_slots.while displaying it show some hash code like [B@43H40 like that, i am using jstl code like <c:out value="${row.avail_time_slots}"/> .what is the mistake i don't know i database console it gives correctly
I am afraid my Java knowledge is poor and out of date so not sure how you would split that up in Java (in php it is simple).
0

This question isn't related to java, but rather SQL queries. You could select all in a table, and only return rows where column aday has the value "TUE".

SELECT * FROM table WHERE aday=TUE

3 Comments

this query gives two rows,but i want to display one rows with all data without duplicatedata
is there a particular row you want, or does it not matter? You could have multiple conditions relating to other columns and their values. If you just want the first row to be returned, do SELECT * FROM table WHERE aday=TUE LIMIT 1
i need both rows data(availfrom ,availupto) in a single column, i edit my question what i am getting currently in front end. i want to display 2nd row availfrom ,availupto beside the first row

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.