I have 2 tables with data. "keywords" and "Data".
key_id (P)
key_word
key_prod (I)
kay_country
key_is_wr
and
id (P)
dat_id (I)
dat_date
dat_is_weekly
For each keyword there are a few different rows linked in the data table - with different or the same dates in dat_date. I want to get all variations of dates that exist in this table only once so i can display them all in an array on my PHP code.
This is the query im currently using - it gets me a list of the same dates from the specific "key_app" value I need. But I only want to get an array of dates that exist for this specific key_id.
SELECT * FROM `keywords`
JOIN `data`
ON `keywords`.`key_id` = `data`.`dat_id`
WHERE `keywords`.`key_app`= 10
I Just haven't figure out yet how to:
1. Get only the dat_date section (I guess i need data.dat_date instead of the "*" in my query.
2. How to get only the different dates that exist for each key_prod.
I tried using all sorts of ORDER BY and MAX(id) and nothing seem to work well in terms of sytaxes
SELECT * FROM `keywords`
JOIN (
SELECT MAX(id) AS id
FROM `data`
GROUP BY `data`.`dat_date`
) `keywords`
ON `keywords`.`key_prod`=10
I have been digging it for a while but no right result
Example:
If I have under dat_date the vars
2016-06-21
2016-06-21
2016-06-21
2016-06-22
2016-06-22
2016-06-23
2016-06-23
for a specific key_app - I will get:
2016-06-21
2016-06-22
2016-06-23
as a query result