simple query question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

simple query question

Post by speedy33417 »

I have a query where I want to get the value of address_id from a table. address_id is not the primary_key and is not unique.

Code: Select all

$sql = "SELECT address_id FROM thistable WHERE date > '$searchDate'";
A query like above will result in values like so:

1
12
45
12
25
25
45

Is it possible to get the values only once. Like so:
1
12
45
25

Thx.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You could use the DISTINCT keyword.

Code: Select all

select distinct `address_id` ...
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Re: simple query question

Post by jimthunderbird »

or using the group by statement, but i think select distinct might be faster
Post Reply