MySQL - SELECT all columns WHERE one column is DISTINCT

2012-07-25T08:52:59

I'm very sorry if the question seems too basic.
I've surfed entire Internet and StackOverflow for a finished solution, and did not find anything that I can understand, and can't write it myself, so have to ask it here.

I have a MySQL database.
It has a table named "posted".
It has 8 columns.

I need to output this result:

SELECT DISTINCT link FROM posted WHERE ad='$key' ORDER BY day, month

But I need not only the "link" column, but also other columns for this row.
Like for every row returned with this query I also need to know its "id" in the table, "day" and "month" values etc.

Please tell me what should I read to make it, or how to make it.
Please keep it as simple as possible, as I'm not an expert in MySQL.

Edit: I tried this:

SELECT DISTINCT link,id,day,month FROM posted WHERE ad='$key' ORDER BY day, month

It doesn't work. It returns too many rows. Say there are 10 rows with same links, but different day/month/id. This script will return all 10, and I want only the first one (for this link).

Copyright License:
Author:「John Smith」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/11641270/mysql-select-all-columns-where-one-column-is-distinct

About “MySQL - SELECT all columns WHERE one column is DISTINCT” questions

I'm very sorry if the question seems too basic. I've surfed entire Internet and StackOverflow for a finished solution, and did not find anything that I can understand, and can't write it myself, so...
So I'm reading this answer about selecting all columns of a table where only one of them is distinct, and it's exactly what I need, but unfortunately it's a MySQL question and not a django question...
I have to display result with select multiple column but distinct on only one column i have also used following queries and also refereed below link. Query One. select category , offer_id, store_...
My aim is to use distinct on one column but return all the columns. My table is like this id, name, year 1, John, 2012 2, Jake, 2012 3, Jenna, 2013 1, John, 2013 I need to do distinct on id ..
I am using Netezza (based on PostgreSQL) and need to select all columns in a table for rows distinct on one column. A related question with answer can be found here, but it doesn't handle the case ...
I want to select each available entry for each column once. This problem was solved with SELECT DISTINCT a from my_table UNION SELECT DISTINCT b from my_table UNION SELECT DISTINCT c from my_table...
I am using Oracle SQL and am trying to get all columns returned when querying for distinct values on a particular column. I've tried using other answers I've found on here but I am not getting as ...
I'm a newbie in MySQL. I'm writing a code where I need to select only one table as distinct and return all tables. Here is my database image... Here is my MySQL query... `SELECT DISTINCT
I have a MySQL query in PHP where I am getting all distinct values and then getting the sums of associated columns of these distinct values like this: SELECT t.`fruits`,sum(coalesce(s.amount,0)),...
I have a table which looks like this: NAME Col1 Col2 Col3 Tim 1 2 3 Tim 1 1 2 Tim 2 1 2 Dan 1 2 3 Dan 2 2 ...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.