?
Solved

Mysql Query

Posted on 2000-04-13
2
Medium Priority
?
241 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 272 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

840 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