i just tried it and your example works great. I would still like to
understand it more so i can use it further.
what if you wanted to do the same thing but with a work.
like you searched the listings for a keyword, and wanted to return a
weighted result.
If the table has a title, and a description which we will call l_title
and l_desc and you search looking for a keyword so, where l_title or
l_desc = 'keyword' and then want to order by if the keyword matches the
title first and then the desc. Wouldn;t this give "weight to the title"
I just dont understand the 0, 1 at the end of the if yet to modify it.
Could something like this work?
Thanks for your help.
Chad
chadsmith76@gmail.com wrote:[color=blue]
> Hey Gordon,
>
> I didn't know you could put if() ststements into a SELECT. I will give
> that a try. yes NULL not blank thanks for that, and the coords in
> general are both positive and negative values, and if it is blank or
> NULL obviously it wouldn't be + or - .
>
> how does the if work exactly in a SELECT? you wrote "ORDER BY
> if(l_xcoord<>0, 0, 1), l_xcoord" So we have if(item<>value, 0, 1)item
> does this mean 0 is like true and 1 is false or do the numbers mean
> something else like number value lengths??? And then i just put the
> order by l_xcoord after it? Can you explain how it works?
>
> I use if statements in php but don't recognize the 0, 1 in it.
>
> Thanks,
>
> Chad
>
> Gordon Burditt wrote:[color=green][color=darkred]
> > >I have listings with coordinates, i would like to do ORDER BY and
> > >display listings with coords first.
> > >If they don't have coords the value
> > >is blank and the coords go both positive and negative values.[/color]
> >
> > If they don't have coords the values that the coords don't have
> > can be positive or negative? Huh? Also, there's no such value
> > as "blank" for a numeric field. Null, yes, blank, no.
> >[color=darkred]
> > >So i
> > >tried an "ORDER by l_xcoord HAVING l_xcoord<>0" but this is acting like
> > >a WHERE statement removing all results with no coords. I tried GROUP BY
> > >as well but same results...[/color]
> >
> > ORDER BY if(l_xcoord<>0, 0, 1), l_xcoord
> >
> > should do what I think you want.
> >[color=darkred]
> > >
> > >So the question is how can i display all results with the ones that
> > >have coords first? It seems like it should be simple but I'm just not
> > >seeing it.[/color]
> >
> > The trick here is to come up with an expression you can put earlier
> > in the sort order which distinguishes the cases you want.
> > if(l_xcoord<>0, 0, 1) has the value 0 if there are coordinates, 1
> > if there are not.
> >
> > Gordon L. Burditt[/color][/color]