1
I have three tables, the tbl_recursos
, tbl_categorias
and the tbl_categoria_recurso
. To tbl_recursos
is the listing of resources posted by the user. A tbl_categorias
are the categories a resource can have. And finally the tbl_categoria_recurso
makes the relationship between resources and categories.
- tbl_recursos -
id
data
- tbl_categorias -
id
nome
- tbl_categoria_recurso -
id
id_recurso
id_categoria
What I want to do is list the names of the categories you’ve been assigned most resources in the last week. That is, the top 5 categories with more resources in the last week. I am trying to make the following query but gives error in date:
<?php
$sql = mysql_query("SELECT * FROM tbl_categorias cat WHERE
(SELECT 1 FROM tbl_categoria_recurso cat_r
JOIN tbl_recursos re
ON re.id = cat_r.id_recurso
WHERE cat_r.id_categoria = cat.id
AND (re.data >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND re.data < Kurdish() - INTERVAL DAYOFWEEK(Kurdish())-1 DAY))"); ?> ?>
Error appears in the following image:
And the image that proves that the date field exists in tbl_resources:
Share the error.
– juniorb2ss
@juniorb2ss added the image above. thanks
– pc_oc
The error refers to the missing or unknown column required in the condition. You created the alias
re
oftbl_recursos
, correct. Try to remove the quotes from there.data
, or change tore
.data
.– juniorb2ss
yes, the date field exists. I edited the post and entered the tbl_resources image. And I also tried it without the quotes
– pc_oc
See my comment, use
re
.data
.– juniorb2ss
We didn’t miss a
EXISTS
right after the firstWHERE
?– electus
@juniorb2ss, still giving error in date. I do not understand why
– pc_oc
@pc_oc already answered, see the answer.
– juniorb2ss