Autor Zpráva
unlucky
Profil
Podival jsem se nahoru na FAQ a query mi nejak nefunguje :P

articles - id, article_id
categories - id

hlasi mi unknown column k.id
select c2.* 
from   articles c2 
join   (select k.id, 
               (select id
                from   articles c 
                where  c.article_category= k.id
                order  by id desc 
                limit 4, 1) hranice 
        from   categories k) h on c2.article_category= k.id
                                 and c2.id>= ifnull(h.hranice, c2.article_category) 
DJ Miky
Profil
Při zběžném pohledu by na předposledním řádku asi mělo být:
... on c2.article_category= h.id
unlucky
Profil
jj, dekuji, tam byl ten problem

A kdybych chtel vypsat treba z kategorii 17,20,21 jak to bude?
select c2.*  
from   articles c2  
join   (select k.id,  
               (select id 
                from   articles c  
                where  c.article_category= k.id 
                order  by id desc  
                limit 4, 1) hranice  
        from   categories k where k.id in (17,20,21) 
) h on c2.article_category= h.id 
                                 and c2.id>= ifnull(h.hranice, c2.article_category) 

Lze nejdrive vypsat treba 20 pak 17 a 21?
Mastodont
Profil
Zkus
ORDER BY FIELD(k.id, 20, 17, 21)
unlucky
Profil
mam
select c2.*   
from   articles c2   
join   (select k.id,   
               (select id  
                from   articles c   
                where  c.article_category= k.id  
                order  by id desc   
                limit 4,1) hranice   
        from   categories k where k.id in(20,21,17,27)  ORDER BY FIELD(k.id, 21, 20,17,27) 
) h on c2.article_category= h.id  
                                 and c2.id>= ifnull(h.hranice, c2.article_category)
neserazuje to :(
Kajman
Profil
unlucky:
FAQ a query mi nejak nefunguje
Opraveno i tam.

neserazuje to
Order by nedávejte do poddotazu, tam to neovlivní. Zkuste
select c2.*
from   articles c2
join   (select k.id,
               (select id
                from   articles c
                where  c.article_category = k.id
                order  by id desc limit 4, 1) hranice
        from   categories k
        where  k.id in (20, 21, 17, 27)) h
on     c2.article_category = h.id
       and c2.id >= ifnull(h.hranice, c2.article_category)
ORDER  BY FIELD(h.id, 21, 20, 17, 27), c2.id desc
unlucky
Profil
dekuji, je to perfektni

a v title chybi "ch" :(

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0