I am trying to sort by the values in a: - SELECT idCol FROM myTable WHERE idCol IN (5,7,2,3,16)
So the results would be:
5
7
2
3
16
Now, the results are:
2
3
5
7
16
The values in the IN() are identity column values generated by a Zend search resultant, and are generated in order of weight. This means I must retain that order when querying the database for the rest of the columns associated with the identity column.
Thanks much!!!!
4 1474
I am trying to sort by the values in a: - SELECT idCol FROM myTable WHERE idCol IN (5,7,2,3,16)
So the results would be:
5
7
2
3
16
Now, the results are:
2
3
5
7
16
The values in the IN() are identity column values generated by a Zend search resultant, and are generated in order of weight. This means I must retain that order when querying the database for the rest of the columns associated with the identity column.
Thanks much!!!!
use
SELECT idCol FROM myTable WHERE idCol IN (5,7,2,3,16) order by idCol
I am trying to sort by the values in a: - SELECT idCol FROM myTable WHERE idCol IN (5,7,2,3,16)
So the results would be:
5
7
2
3
16
Now, the results are:
2
3
5
7
16
The values in the IN() are identity column values generated by a Zend search resultant, and are generated in order of weight. This means I must retain that order when querying the database for the rest of the columns associated with the identity column.
Thanks much!!!!
No that is not possible by a simple select query.
You can either SORT ASCENDING or DESCENDING but not random
By the way the IN clause data is hardcoded?
amitpatel66,
It's an ordered list of values returned by Zend Lucene. The order denotes the weight of the result.
So if you search for: "Sports Illustrated", your results might be:
"Sports Store"
"Illustrated Sports Images"
"Sports Illustrated"
"Sports Websites"
etc...
Each is assigned a weight (by Zend). And has a numeric value denoting the value of the corresponding ID column value in the database.
So:
ID | Results Text
837483 | "Sports Store"
82744 | "Illustrated Sports Images"
336764 | "Sports Illustrated"
326183 | "Sports Websites"
Zend returns it by weight. So since "Sports Illustrated" (2336764) is an exact match, it's returned first (but you will notice the ID is NOT first if we sort by ID column -- sorting by ID, in any way, does no good):
336764 | "Sports Illustrated"
837483 | "Sports Store"
326183 | "Sports Websites"
82744 | "Illustrated Sports Images"
I get from Zend: (336764, 837483, 326183, 82744). In that order. Meaning 336764 is closes match, 837483 is next closest, etc.
So I cannot use the ID column as the sort criteria. Only the actual position in the IN() part of the query.
---------
I am going to brute-force it. So if anyone need a less than optimal solution, here's what I am going to do:
1. Make a temp table:
CREATE TABLE TempZend(
IDCol INT,
Position TINYINT
);
2. Stick the Zend results into the table - in order:
INSERT INTO TempZend (336764, 1)
INSERT INTO TempZend (837483, 2)
INSERT INTO TempZend (326183, 3)
INSERT INTO TempZend (82744, 4)
3. Do a JOIN and sort by TempZend.Position.
SELECT * FROM myTable, TempZend WHERE myTable.idCol = TempZend.IDCol ORDER BY TempZend.Position
Sucks, yea. But will work.
If anyone comes up w/ a single kewl SELECT, please post here. I'll keep checking back.
Thanks!!
amitpatel66,
It's an ordered list of values returned by Zend Lucene. The order denotes the weight of the result.
So if you search for: "Sports Illustrated", your results might be:
"Sports Store"
"Illustrated Sports Images"
"Sports Illustrated"
"Sports Websites"
etc...
Each is assigned a weight (by Zend). And has a numeric value denoting the value of the corresponding ID column value in the database.
So:
ID | Results Text
837483 | "Sports Store"
82744 | "Illustrated Sports Images"
336764 | "Sports Illustrated"
326183 | "Sports Websites"
Zend returns it by weight. So since "Sports Illustrated" (2336764) is an exact match, it's returned first (but you will notice the ID is NOT first if we sort by ID column -- sorting by ID, in any way, does no good):
336764 | "Sports Illustrated"
837483 | "Sports Store"
326183 | "Sports Websites"
82744 | "Illustrated Sports Images"
I get from Zend: (336764, 837483, 326183, 82744). In that order. Meaning 336764 is closes match, 837483 is next closest, etc.
So I cannot use the ID column as the sort criteria. Only the actual position in the IN() part of the query.
---------
I am going to brute-force it. So if anyone need a less than optimal solution, here's what I am going to do:
1. Make a temp table:
CREATE TABLE TempZend(
IDCol INT,
Position TINYINT
);
2. Stick the Zend results into the table - in order:
INSERT INTO TempZend (336764, 1)
INSERT INTO TempZend (837483, 2)
INSERT INTO TempZend (326183, 3)
INSERT INTO TempZend (82744, 4)
3. Do a JOIN and sort by TempZend.Position.
SELECT * FROM myTable, TempZend WHERE myTable.idCol = TempZend.IDCol ORDER BY TempZend.Position
Sucks, yea. But will work.
If anyone comes up w/ a single kewl SELECT, please post here. I'll keep checking back.
Thanks!!
This is for one scenario but what about other scenarios.
One more thing I would suggest is to use ORDER BY ROWID will work.
When you do an insert as mentioned in your previous post, in that order, a ROWID will be assigned to each row and ORDER by that ROWID will do. You need not have seperate column called POSITION.
Try this: -
SELECT * FROM myTable, TempZend WHERE myTable.idCol = TempZend.IDCol ORDER BY ROWID
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Christian Gruber |
last post by:
dear NG,
I have a problem sorting the values of a container,
multimap<int, pair<int, double> > map;
where the key element is the first column
and part of the value is the second column.
1 ...
|
by: Elijah Bailey |
last post by:
I want to sort a set of records using STL's sort() function,
but dont see an easy way to do it.
I have a
char *data;
which has size mn bytes where m is size of the record and
n is the...
|
by: ritchie |
last post by:
Hi all,
I am new to this group and I have question that you may be able to
help me with.
I am trying to learn C but am currently stuck on this.
First of all, I have a function for each sort...
|
by: Ali Chambers |
last post by:
Hi,
I have a two arrays that I wish to sort. One is the index array (full
of floating point values). The other is a string array:
ARRAY 1 ARRAY 2
------- --------
-1.2 textA
12 textB...
|
by: phillip.s.powell |
last post by:
Ok, you have three tables. You're supposed to be able to not only sort
(ORDER BY) according to a_name, no problem, but you must also have the
ability to sort (ORDER BY) the relationship between...
|
by: max sharma |
last post by:
Hi all,
I am using a hashtable for my application. Its similar to word count
application. How can I sort the hashtable w.r.t.
the VALUE and not the KEY. The sample data of the table is given below...
|
by: max sharma |
last post by:
Hi all,
I am using hashtable in C# with keys of type string and values of type
double. I am not able to find a way to sort them by value (descending to
be precise) instead of key. Can someone...
|
by: bcochofel |
last post by:
Hi, I want to use a variable to sort elements. That var his passed with
query string (I'm using Perl CGI to generate XML).
Here's a sample of my output:...
|
by: jeremit0 |
last post by:
I'm trying to sort a vector<complex<double and can't figure it
out. I recognize the problem is that there isn't a default operator<
for complex data types. I have written my own operator and can...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |