473,385 Members | 1,523 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,385 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 2739
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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 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.