php - mysql using max as where condition -
i got 4 fields
page_id page_category_id page_sequence page_path
for example
record 1 page_id = 1 page_category_id = 22 page_sequence = 1 page_path = "1.jpg" record 2 page_id = 1 page_category_id = 22 page_sequence = 2 page_path = "2.jpg" record 3 page_id = 1 page_category_id = 23 page_sequence = 1 page_path = "23_1.jpg" record 4 page_id = 1 page_category_id = 23 page_sequence = 2 page_path = "23_1.jpg" record 5 page_id = 1 page_category_id = 23 page_sequence = 3 page_path = "23_1.jpg" .. , more records
i want draw statement that
$sql_select = "select page_category_id my_table max(page_sequence) < 3";
it show page_category_id max(page_sequence) less 3.
but can't max(page_sequence) condition
how can working.. thanks!
sql such fun, since can solve things in several different ways. here's not exists
alternative:
select distinct page_category_id tablename t1 not exists (select 1 tablename t2 t2.page_category_id = t1.page_category_id , t2.page_sequence >= 3)
return page_category_id if there no row same page_category_id has page_sequence >= 3.
Comments
Post a Comment