Select distinct

This is a discussion on Select distinct within the MySQL Database forums, part of the Database Forums category; Hi Folks Here is my SQL code: SELECT * FROM Company INNER JOIN `Properties` ON `Company`.`Company_ID`=`Properties`.`Company_ID` WHERE `Properties`.`...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-16-2007
UKuser
 
Posts: n/a
Default Select distinct

Hi Folks

Here is my SQL code:

SELECT *
FROM Company
INNER JOIN `Properties`
ON `Company`.`Company_ID`=`Properties`.`Company_ID`
WHERE `Properties`.`Property` LIKE '%$clean_search%'
ORDER BY Country
ASC

What I want this to return is a list of all fields: Company & Country
from the table Company. However its returning the same company multiple
times when there are more than 1 Properties.Property LIKE
$clean_search.

What I want but I'm not actually sure if it can be done is a statement
like:

SELECT DISTINCT Company, *

Can this be done?

Thanks

A

Reply With Quote
  #2 (permalink)  
Old 01-16-2007
Captain Paralytic
 
Posts: n/a
Default Re: Select distinct


UKuser wrote:

> Hi Folks
>
> Here is my SQL code:
>
> SELECT *
> FROM Company
> INNER JOIN `Properties`
> ON `Company`.`Company_ID`=`Properties`.`Company_ID`
> WHERE `Properties`.`Property` LIKE '%$clean_search%'
> ORDER BY Country
> ASC
>
> What I want this to return is a list of all fields: Company & Country
> from the table Company. However its returning the same company multiple
> times when there are more than 1 Properties.Property LIKE
> $clean_search.
>
> What I want but I'm not actually sure if it can be done is a statement
> like:
>
> SELECT DISTINCT Company, *
>
> Can this be done?
>
> Thanks
>
> A


Try:

SELECT DISTINCT `Company`.*
FROM `Company`
INNER JOIN `Properties` USING(`Company_ID`)
WHERE `Properties`.`Property` LIKE '%$clean_search%'
ORDER BY Country ASC

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:35 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0