Click here to get back home

DISTINCT with multiple tables and INNER JOIN ?

 HomeNewsGroups | Search | About
 mailing.database.mysql    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
DISTINCT with multiple tables and INNER JOIN ? . 09-19-2006
Get Chitika Premium
Posted by . on September 19, 2006, 9:41 am
Please log in for more thread options
My query works OK this way, but I need every "kohde_name" only once
(preferred the earliest "hav_date").
I've tried with "DISTINCT kohde_name" in many ways, but always end up with
syntax error...:(
Is there any solution with DISTINCT, or do I need anotjer solution?

my (simplified) query:
SELECT henk_name,henk_number, kohde_name
,kohde_txt,havainto_id,hav_kohdetxt, hav_date
FROM ((henkilo INNER JOIN havaitsija ON hja_henkilo_id=henkilo_id)
INNER JOIN havainto ON hja_havainto_id=havainto_id)
INNER JOIN kohde ON hav_kohde_id=kohde_id
WHERE ...

Tommi.P.



Posted by strawberry on September 20, 2006, 9:29 am
Please log in for more thread options

. wrote:
> My query works OK this way, but I need every "kohde_name" only once
> (preferred the earliest "hav_date").
> I've tried with "DISTINCT kohde_name" in many ways, but always end up with
> syntax error...:(
> Is there any solution with DISTINCT, or do I need anotjer solution?
>
> my (simplified) query:
> SELECT henk_name,henk_number, kohde_name
> ,kohde_txt,havainto_id,hav_kohdetxt, hav_date
> FROM ((henkilo INNER JOIN havaitsija ON hja_henkilo_id=henkilo_id)
> INNER JOIN havainto ON hja_havainto_id=havainto_id)
> INNER JOIN kohde ON hav_kohde_id=kohde_id
> WHERE ...
>
> Tommi.P.

OK, I'm guessing a bit at your table structure here - not helped by my
decidedly limited knowledge of Finnish, but see if you can adapt this
to your needs (maybe as a derived table onto which everything else is
joined:

SELECT hto1 . *
FROM havainto hto1
LEFT JOIN havainto hto2 ON hto1.hav_kohdetxt = hto2.hav_kohdetxt
AND hto1.havainto_id <> hto2.havainto_id
AND hto1.hav_date < hto2.hav_date
WHERE hto2.hav_date IS NULL


Similar ThreadsPosted
getting two distinct fields from one tbl from a join query of two tables November 15, 2006, 9:28 am
SUM(DISTINCT) OF INNER JOIN December 14, 2005, 8:06 am
DISTINCT with multiple columns? November 21, 2005, 1:19 pm
Self join to multiple references... October 25, 2005, 2:41 pm
join tables? August 20, 2006, 3:21 am
Query from multiple tables October 15, 2005, 6:29 pm
Importing XML into multiple tables? July 11, 2006, 5:02 am
help with SQL coding question - 3 tables with outer join needed January 23, 2006, 1:07 pm
Odd query from multiple tables (brainbuster) April 26, 2006, 8:27 am
help needed with select statement from multiple tables January 8, 2006, 4:11 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap