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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.