Re: SELECT with Result Ordered by Minimum of Fields

2006-08-06 Thread Chris W

David T. Ashley wrote:


Can I just write something like:

SELECT * FROM mytable WHERE fieldofinterestvalue ORDER BY MIN(field1,
field2) ASC;



I think this will work..

SELECT *, IF(a-b  0,a, b) as SortField
FROM table
WHERE whatever
ORDER BY SortField

a and b being the names of the fields you are interested in.

--
Chris W
KE5GIX

Gift Giving Made Easy
Get the gifts you want  
give the gifts they want
One stop wish list for any gift, 
from anywhere, for any occasion!

http://thewishzone.com


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: SELECT with Result Ordered by Minimum of Fields

2006-08-06 Thread David T. Ashley

On 8/6/06, Chris W [EMAIL PROTECTED] wrote:


David T. Ashley wrote:

 Can I just write something like:

 SELECT * FROM mytable WHERE fieldofinterestvalue ORDER BY MIN(field1,
 field2) ASC;


I think this will work..

SELECT *, IF(a-b  0,a, b) as SortField
FROM table
WHERE whatever
ORDER BY SortField



Question:  Is there any way to get SortField (or a similar
per-selected-record field) included with the SELECT output?

The reason for this inquiry is that my PHP script that uses the SELECT
results will also have to calculate SortField as MySQL did as part of the
query.  If MySQL has done it already, no need to do it a second time in the
PHP script.

Thank you.


Re: SELECT with Result Ordered by Minimum of Fields

2006-08-06 Thread Chris W

David T. Ashley wrote:


On 8/6/06, Chris W [EMAIL PROTECTED] wrote:



David T. Ashley wrote:

 Can I just write something like:

 SELECT * FROM mytable WHERE fieldofinterestvalue ORDER BY MIN(field1,
 field2) ASC;


I think this will work..

SELECT *, IF(a-b  0,a, b) as SortField
FROM table
WHERE whatever
ORDER BY SortField




Question:  Is there any way to get SortField (or a similar
per-selected-record field) included with the SELECT output?

The reason for this inquiry is that my PHP script that uses the SELECT
results will also have to calculate SortField as MySQL did as part of the
query.  If MySQL has done it already, no need to do it a second time 
in the

PHP script.


If you run that select in MySQL query browser you will see that in 
addition to all the other fields in the table it adds to the end  a 
field called SortField.  If you would like it at the beginning they 
change it to .


SELECT IF(a-b  0,a, b) as SortField, *

If you want it the middle you will need to list every field in the 
select with the SortField if between the 2 you want it between



--
Chris W
KE5GIX

Gift Giving Made Easy
Get the gifts you want  
give the gifts they want
One stop wish list for any gift, 
from anywhere, for any occasion!

http://thewishzone.com


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



SELECT with Result Ordered by Minimum of Fields

2006-08-05 Thread David T. Ashley

Hi,

I have a table and I'd like to do a SELECT query with the result ordered by
the minimum of two fields.  I might also like to query by the minimum (but
that is an easier problem, as I can just rephrase it as an OR).

Can I just write something like:

SELECT * FROM mytable WHERE fieldofinterestvalue ORDER BY MIN(field1,
field2) ASC;

or is it more complicated or impossible?

Thanks, Dave.