Solved

Mysql Query

Posted on 2000-04-13
2
208 Views
Last Modified: 2006-11-17
Here is my mysql question :

I have 3 tables :

create table Categorie (
      IDCat bigint(21) NOT NULL auto_increment,
      Cat varchar(255) NOT NULL,
      PRIMARY KEY (IDCat)
)\p\g

create table Region (
      IDReg bigint(21) NOT NULL auto_increment,
      Reg varchar(255) NOT NULL,
      PRIMARY KEY (IDReg)
)\p\g

create table Agenda (
      IDAgen bigint(21) NOT NULL auto_increment,
      IDCat bigint(21) NOT NULL,
      IDReg bigint(21) NOT NULL,
      Descrip varchar(255) NOT NULL,
      PRIMARY KEY (IDAgen)
)\p\g

I have this query :
$result = mysql_query("SELECT Categorie.IDCat,Categorie.Cat FROM Categorie left join Agenda on Agenda.IDCat = Categorie.IDCat where Agenda.Descrip <> '' and Agenda.IDReg = '2'", $db);

This query returns several record that contains the same value, I would like them to be listed only one time.  How could I do that?

Thank you



0
Comment
Question by:cybernietic
2 Comments
 
LVL 8

Accepted Solution

by:
us111 earned 68 total points
ID: 2711154
Your table definition is not really useful :)

Just add the DISTINCT function in your mysql query.
$result = mysql_query("SELECT DISTINCT Categorie.IDCat,Categorie.Cat FROM Categorie left join Agenda on Agenda.IDCat =
                      Categorie.IDCat where Agenda.Descrip <> '' and Agenda.IDReg = '2'", $db);

DISTINCTROW is you have several same records.

0
 
LVL 1

Author Comment

by:cybernietic
ID: 2714982
Excellent! Thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now