0

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

1
  • Is your issue solved? Commented Nov 27, 2016 at 17:27

1 Answer 1

1

Try this.

select distinct data.dat_date
FROM `keywords`, `data` 
ON `keywords`.`key_prod` = `data`.`dat_id`
WHERE `keywords`.`key_app`= 10

Your first query was how to display only the date. This can be done using select data.dat_date instead of select *. Distinct will list only distinct dates not the same dates which was your query 2.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.