Jump to content

Help with JOIN


dbk

Recommended Posts

Hi

 

I need some help with a query that don't work:

 

SELECT * FROM contact JOIN project_contact USING (contact_id) WHERE project_id = 1301

 

I have two tables - "contact" and "project_contact".

"contact" contains some information about people.

"project_contact" contains information about wich projects a contact is linked to.

 

Both tables has a column  "contact_id".

 

But the "project_contact" table has also a column "project_id" that I want to sort the contacts with!!!

 

If you understand the explanation :wtf: what am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/205102-help-with-join/
Share on other sites

Well, you state you want to use the project_id to "sort" the records, but your query is currently filtering the records. Other than that, I see no obvious problems. Although, if there are other columsn with duplicate names between the tables that would cause an error. You don't state if you are getting any errors. If so, please post them.

 

If you really do want to sort instead of filter the query would look something like this:

SELECT *
FROM contact
JOIN project_contact USING (contact_id)
ORDER BY project_id

Link to comment
https://forums.phpfreaks.com/topic/205102-help-with-join/#findComment-1073646
Share on other sites

Hi mjdamato

 

Sorry for my english.. What I want is to filter using the "project_id" !

each contact can be linked to many projects and thats why I made the "project_contact" table that only contain a primary key with autoincrease, the contact_id and the project_id.

 

Hope it makes sense!

 

By the way.. I don't get any error using: SELECT * FROM contact JOIN project_contact USING (contact_id) WHERE project_id = 1301

The filter just don't work!!

 

Link to comment
https://forums.phpfreaks.com/topic/205102-help-with-join/#findComment-1073786
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.