Jump to content

How do I write this in a single query?


Perad

Recommended Posts

Could someone briefly explain what primary keys are? I use them all the time. Are they just a unique identifier for the record or do they have a deeper meaning?

 

Futhermore I have recently heard the word 'foriegn key' bounded around. Anyone know what this is?

 

Regarding the Query. I have 3 tables.

 

Users

Groups

Tax

 

They look something like this.

 

Users

- id

- name

- pass

- email

 

Groups  // Stores Members/Groups relations

- user_id

- group_id

 

Tax // Stores name/id relationships. In this case type=Group; name=Group Name; tax_id=group_id

- tax_id

- type

- name

 

What I want to do is get userdata. This includes group data. Whats the best way to query the username, get the group the user is a member of, get the name of that group?

Link to comment
https://forums.phpfreaks.com/topic/118240-how-do-i-write-this-in-a-single-query/
Share on other sites

A primary key is simply a unique identifier of a record -- for example, if you had records with SSNs, you might not need to add a UID field (a.k.a. a surrogate key).

 

As for the 2nd question, you simply need to join by following the *_id fields.

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.