Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Mysql Query

Posted on 2000-04-13
2
220 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

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

Suggested Solutions

Title # Comments Views Activity
Cookie not unsetting 7 27
php help 34 58
PHP breaks when used in Wordpress template file 3 30
Row insertion failed. Array 5 46
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

856 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