Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
In one table one coloumn name is "Name". This name coloumn has 20 records. First ten records contain the value as "surender". Next ten records contain the value as "govind". I want the query to display the 1st record as "surender" and 2nd record as "govind" and 3rd record as "surender" 4th record as "govind" . like that means alternatively display the names. please tell me the query.
What if you simply query the database with two simple selects:
SELECT name FROM table WHERE name = 'surrender' SELECT name FROM table WHERE name = 'govind'
This would give you all the records from each case. Now just loop through the ResultSets and interleave them.
You could also just do a simple: SELECT name FROM table and then just use some Java logic on the ResultSet to get the data how you want it.
I don't know of anything in SQL to group the data like that, most of the time I am trying to sort like items together. I never tried alternating, I am not sure if SQL can do this, I will be interested to see what others come up with.
That may not be the best solution, but I think it could work. Maybe someone has some SQL mastery to solve this otherwise(I'm not great at SQL, just know enough to get by).
It might help to have some more background, why do you need to alternate the data? What else is i the table? I'm not sure if I really understand what you are getting here.
Sahidul, Can you describe the problem you are trying to solve a bit more? In particular, if there is something more abstract. The current problem can be solved by hard coding which clearly isn't what you want.