Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php mysql query - select 2 distinct columns treat as one

Status
Not open for further replies.

Wickersty

Programmer
Nov 13, 2002
51
0
0
US
Good afternoon,

If I have a table in which are two colums job1 and job2. Both have the same possible values (ie job1 can be either cook, tv host, or sales and job2 can be ither cook, tv host, or sales).

I want to create a querie that says select DISTINCT jobs from job1 and job2... meaning, give me a list of all distinct jobs from both columns... keeping in mind that if "cook" is a distinct job from a job1 record, I dont want to pick up "cook" again from any job2 records.

Can someone help with this? I can't quite figure it out.

Thanks,

Jeff
 
Just as a note:
I think your table should be structured differently - the probelm arises from the fact that unique information needs to be extracted from two different colums. There is a hardcoded 2-jobs limit in your table.
A more open setup with a foreign key for the job title would solve your problem. Similar information belongs in the same column.
 
I think I know a way to accomplish this, but I need to clarify:

if the table looks like this:

Code:
+-------+-------+
| val_1 | val_2 |
+-------+-------+
| abc   | def   |
| abc   | def   |
| abc   | abc   |
| def   | ghi   |
| xyz   | abc   |
+-------+-------+

What are you wanting your result set to look like?

Suggestions:

Code:
+-------+
| abc   |
| def   |
| ghi   |
| xyz   |
+-------+

+-------+-------+
| abc   | def   |
| def   | ghi   |
| xyz   | abc   |
+-------+-------+

Can you clarify what exactly you want the results of your query to look like, if the table has duplicate values like above, so I can make a better effort at this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top