php - MySQL LIMIT 1 but query 15 rows? -


basically i'm trying compare id's of rows against 15 results in mysql, eliminating 1 (using not in) , pull result.

now fine itself, order of 15 rows i'm doing sql query changing based on ranking, there possibility between time ranking updates, , ajax request (which submit id's not in) more 1 id has changed, of course bring more 1 row not want.

so in short, there way in can query 15 rows, return one? without having run 2 separate queries. appreciated, thank you.

example:

say have 7 items in database, , i'm displaying 5 on page user.

these being displayed user:

apple orange kiwi banana grape 

but in database have

peach blackberry 

now want if user deletes item list, add item (based on ranking have)

now issue is, in order know have on list @ moment send remaining items database (say deleted kiwi, send apple, orange, banana, , grape)

so select highest ranked 5 items remaining 6 items, make sure not ones displayed on page, , add new 1 list (either peach or blackberry)

all , well, except if both peach , blackberry outrank grape, returning 2 results instead of one. because would've queried...

apple orange banana peach blackberry 

and excluded...

apple orange banana grape 

which leaves both peach , blackberry, instead of peach or blackberry

i'm not sure understood requirements, i'll give try. following example based on understanding, , assumes want display top five rows.

select   ul.itemname   userlist ul   (ul.deleted = 0) -- take items not deleted  union -- union clause discards duplicate entries, unlike union  select   i.itemname   (select     il.itemname       itemlist il -- table containing items   order     il.ranking asc -- important items first, supposing lower number in ranking means higher priority   ) limit 5 -- display top 5 entries 

note: query untested, , there's chance won't return items in correct order, since lacks order clause. therefore, should taken suggestion , not complete solution.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -