RE: Single occurance of data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You really need to research join types for this.  INNER JOIN, INNER LEFT,
OUTER RIGHT etc.  There are a plethora of examples and options on the web.
Also, the DISTINCT keyword might help, as in "select DISTINCT department";

this would return only those departments in courses that have a
corresponding department in departments...
$query = "select departments.department, courses.department from courses
left join departments on departments.department=courses.department";

this would return departments in courses regardless of whether they have a
corresponding department in departments...
$query = "select departments.department, courses.department from courses
left outer join departments on departments.department=courses.department";

this would return the distinct departments in course (without any joins)
$query = "select distinct departments from courses"

There is much more to learn however.


Regards,

    J



-----Original Message-----
From: Alex Francis [mailto:afrancis@camerondesign.co.uk] 
Sent: Tuesday, November 26, 2002 2:54 PM
To: php-db@lists.php.net
Subject:  Single occurance of data


I have two tables in my database with a department name.
One table (department), the name only appears once and it includes all
departments in the school. In the other table, (courses) department can
appear several times, but not all departments will be in the table.

I used the following code to try to get the names of the departments from
the courses table, but unfortunately I get all occurences of the department.
Can someone help me get ony one occurrence of each department from the
courses table.

$query = "select departments.department, courses.department from
departments, courses where departments.department=courses.department";
$result = mysql_query($query);




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux