473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can this be done with a query

Lets say I wanted to select all employees and list their occupations.
I have this query:
SELECT * FROM employees, job WHERE employees.id=job.id

Now some employees might have more than one job. I use PHP to loop through
the results and get this:

Bob
- Driver
Bob
- Cleaner
Dave
- Writer
Mike
- Director
Mike
- Producer

How do I group it to output like this, and can it be done in the query?
Bob
- Driver
- Cleaner
Dave
- Writer
Mike
- Director
- Producer

FYI, My PHP
while($row=mysql_fetch_array($sql)){
echo "$row[name]<br>";
echo " - $row[job]<br>";
}

Appreciate any feedback.

Yobro
Jul 20 '05 #1
1 1265
sks

"YoBro" <yo***@wazzup.co.nz> wrote in message
news:DN********************@news.xtra.co.nz...
Lets say I wanted to select all employees and list their occupations.
I have this query:
SELECT * FROM employees, job WHERE employees.id=job.id


You didn't specify what the id column is, but assuming its the primary key,
why are you joining these tables on the primary key ?

Assuming each employee can have more than one job and each job can only be
assigned to one employee, then you want something like

select * from employees e join job j on e.id=j.employee order by e.name
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: YoBro | last post by:
Lets say I wanted to select all employees and list their occupations. I have this query: SELECT * FROM employees, job WHERE employees.id=job.id Now some employees might have more than one job. I...
3
by: David Mills | last post by:
Hello, looking for some input on how to do this query. (I'm using Access) John Doe 123 Main St Chicago 123 John Doe 123 Main St Chicago 456 John Doe 123 Main St Chicago 789 Given the...
3
by: Matthew Kramer | last post by:
How would be the best way to do this in Access? I have two tables. The first table has all the rows of data. The first column of this table has a country name, the second has a year and the...
4
by: sparks | last post by:
We have a database that reads in and formats raw data. We were using queries to format the data per person and outputing reports. The other database has the persons personal information. I changed...
6
by: Mike | last post by:
I'm creating a dataset and get my data from the db table such as PA, PA, WA, WA CA, DE, DE, DE, FL, WI. is there a way to do a select on that dataset and populate a drop down box such as CT, DE,...
3
by: Miguel Dias Moura | last post by:
Hi, When I subscribe a web site I usually receive an email to confirm my subscription. Only after I follow the link in the email my account gets activated. In general, how is this done? Can...
3
by: Danny Nielsen | last post by:
Hi I am having trouble figuring out how to use combobox in a datagridview. What seemed to be a simple task turned out not to arrghh. I have a dataGridView with 4 columns, one of them is column...
5
by: darnnews | last post by:
Hi, I have been creating a database to keep track of press clippings, but I have hit a couple stumbling blocks. Any help is much appreciate. 1) Seeing if my query is done I have the...
7
by: isdeveloper | last post by:
Hi All, I have a problem with a table that I want to get nice data out of in a single query. The guys here reckon it can't be done in a single query but I wanted to prove them wrong !!...
5
by: dee | last post by:
I would like to update one specific table field in each of 8 records, using different data for each. Is it possible to update one field in 8 different records in one query?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.