in reply to perl sql to separate and sort the column separately?
I am not sure i understand the issue here. I'm having a hardtime understanding it from you example and explanation.
Now, some general comments on you code:
$DBH = &connect or die "Cannot connect to the sql server \n";
This is mysql, right? SQL Server is another product and may confuse you at a later date. Consider changing the message to "Cannot connect to database."
datas
A nitpick, but, "datum" is singular, "data" is plural. "Datas" is just plain wrong. :) Although rarely done, if you want to be correct, change the columns to "datum1" and "datum2" and call the table "data".
There is no reason to place the query-parts in parenthesis. UNION ALL works just fine without them.
The second query-part does not need aliases. They will be ignored anyway. Column names in a UNION (ALL) always follow the names in the first query-part.
Both subtables are aliased "new". While the name is not referred to, and context will separate them, it is best to use different names to avoid confusion. Further, the name "new" is a poor choice, as it is often a keyword and can cause errors or confusion.
While there is an ORDER BY in the sub-queries to help with LIMIT and OFFSET, there is no ORDER BY on the outer query. Usually this isn't a problem, as a UNION ALL places this results of the second part after those of the first part. But this is not how it has to be, it just happens to work out that way. If order is important, you should put an ORDER BY on the outer query, and remember to use column ordinals and not names there, unless your RDBMS supports names there.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: perl sql to separate and sort the column separately?
by afoken (Chancellor) on Apr 13, 2017 at 04:47 UTC |