473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

order by difference - possible?

Hi,

I'm trying to do a MySQL Query using Mysql 3.23.58 something like that below

SELECT name FROM customers WHERE name LIKE "Fred" ORDER BY
difference(name,"Fred");

The difference piece doesn't seem to be working (Syntax Error returned). Is
this not possible without upgrading the server? or am I doing something
wrong, all I want to do is be able to return the results closest to that
entered first.

Thanks in advance

John
Jul 20 '05 #1
4 2740
John Harman wrote:
SELECT name FROM customers WHERE name LIKE "Fred" ORDER BY
difference(name,"Fred");


Try something like:

select difference( 'Fred', 'Fred' );

To see if the function you are trying to use works. If the function
works, there are better changes that the real query with the function
works also. If it doesn't work, then there is no way that the query
would work with it.

I have never seen the difference() function and I was not able to find
it from the MySQL manual, where did you find it?
Jul 20 '05 #2
Hi,

Good idea, still returns the same syntax error.

Looking elsewhere, I think difference is part of the Spatial functions being
added with 4.1

Any ideas how I could achieve the same effect without it?

Thanks for your help so far.

John
"Aggro" <sp**********@yahoo.com> wrote in message
news:b9***************@read3.inet.fi...
John Harman wrote:
SELECT name FROM customers WHERE name LIKE "Fred" ORDER BY
difference(name,"Fred");


Try something like:

select difference( 'Fred', 'Fred' );

To see if the function you are trying to use works. If the function
works, there are better changes that the real query with the function
works also. If it doesn't work, then there is no way that the query
would work with it.

I have never seen the difference() function and I was not able to find
it from the MySQL manual, where did you find it?

Jul 20 '05 #3
John Harman wrote:
I'm trying to do a MySQL Query using Mysql 3.23.58 something like that below

SELECT name FROM customers WHERE name LIKE "Fred" ORDER BY
difference(name,"Fred");

The difference piece doesn't seem to be working (Syntax Error returned). Is
this not possible without upgrading the server? or am I doing something
wrong, all I want to do is be able to return the results closest to that
entered first.


How about this?

SELECT C.name
FROM customers C
WHERE C.name LIKE 'Fred'
ORDER BY
ABS(ORD(UPPER(SUBSTRING(C.name,1,1)))
- ORD(UPPER(SUBSTRING('Fred',1,1)))),
ABS(ORD(UPPER(SUBSTRING(C.name,2,1)))
- ORD(UPPER(SUBSTRING('Fred',2,1)))),
ABS(ORD(UPPER(SUBSTRING(C.name,3,1)))
- ORD(UPPER(SUBSTRING('Fred',3,1)))),
ABS(ORD(UPPER(SUBSTRING(C.name,4,1)))
- ORD(UPPER(SUBSTRING('Fred',4,1))));

This is a hack -- it isn't scalable to an arbitrary depth of similarity
between strings, but after 4 or 5 characters, it might be adequate to
sort your dataset accurately.

Regards,
Bill K.
Jul 20 '05 #4
Aggro wrote:
John Harman wrote:
SELECT name FROM customers WHERE name LIKE "Fred" ORDER BY
difference(name,"Fred");


SELECT name FROM customers WHERE name LIKE '%Fred%'
^^^^^^^^

--
Edd Benson
eb****@netscape.net

amoebae leave no fossils
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Harman | last post by:
Hi, I'm trying to do a MySQL Query using Mysql 3.23.58 something like that below SELECT name FROM customers WHERE name LIKE "Fred" ORDER BY difference(name,"Fred"); The difference piece...
0
by: Tom | last post by:
Using AccessXP - Access2000 In my application, when an order is entered, inventory is automatically adjusted, a pull list is created, items are pulled to fill the order, and the order is...
9
by: copx | last post by:
I wonder if something like this would be save/portable: m = find_slot(); if (m != NOT_FOUND && list.state == OK) { ... The question is: Is it guaranteed that the "list.state == OK" check...
19
by: Yoon Soo | last post by:
Hi, there while mixing assembler and c code I got the following question: struct bar { int bar_val1; int bar_val2; (...) }
4
by: Frank Wallingford | last post by:
Note: For those with instant reactions, this is NOT the common "why is i = i++ not defined?" question. Please read on. I came across an interesting question when talking with my colleagues....
5
by: Ricky W. Hunt | last post by:
VB.NET seems to be processing things in a different "order" than I'm used to. For example, I had a problem (I don't have the exact code handy anymore so it's just a "guess") where if I put the...
21
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
104
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through...
3
by: rcamarda | last post by:
Does the order of columns make a difference in the GROUP BY? Woulde GROUP BY A, B, C return different results than GROUP BY C,A,B ?
32
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.