473,320 Members | 2,158 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,320 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 1416
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...
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.