Jump to content

its possible to select only one value from each row


Nati323
 Share

Recommended Posts

sorry on the topic, i dont know how to explain my self :X: .

lets assume that i have table like this:

	ID	MONTH-------------------------------	1    |    1	2    |    1	3    |    2

now , i want to select the all rows BUT only one from every MONTH, i mean the result should be:

	ID	MONTH-------------------------------	1    |    1	3    |    2

the row with id 2 , dosent get in the result because the MONTH column of ID 2 equal to MONTH in ID 1.

how can i do this?

if you dont understand me please say and i will try to explain my self better.

Edited by Nati323
Link to comment
Share on other sites

ok a few que's,

when i use DISTINCT, like this for example:

SELECT DISTINCT COL1, COL2

the COL2 will be DISTINCT to?

next que i wondering how i do the next one, i have a table with YEAR col and MONTH col look like this:

YEAR - MONTH------------ 2015 | 3 2014 | 3 

now, if i do DISTINC to the MONTH column i get only one year, but i want both

and if i do DISTINC to the YEAR col so i get only one month from every year

how can i do that i get from every year distincs months?

 

i never understand GROUP BY :|

Link to comment
Share on other sites

Distinct means that it will return distinct records. If you say distinct year, month then it will return records that have a distinct combination of the 2 columns. That means that you might have 2 records that have 2014 if the months are different, or you might have 2 records that have month 3 if the years are different, but you won't have 2 records that have the same month and year. If you want a list of distinct years, and also a list of distinct months, then you need to run 2 queries.

Link to comment
Share on other sites

amm, about 2 queris , this not what i want, i dont want list of distinct years alone and list of distinct months alone,

i want a combination like you say in the start of your msg, how can i do that?

because from what i saw its not possible to distinct two columns in one query...

Link to comment
Share on other sites

Using distinct will cause the entire result set to be distinct. If you select 2 columns, then they will be distinct, you won't get a result that has 2 records with the same values in each column. That's just a normal distinct query.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...