Jump to content

SQl creation problem


Erwin007
Go to solution Solved by Barand,

Recommended Posts

$query = "SELECT * FROM  `sales` WHERE rep_id = 

$query = "SELECT * FROM `reps` WHERE rep_touroperatorid = '5' 

I have difficulty explaining it but will try:
I need to select all sales where all the reps have the rep_touroperatorid 5

How to "join" or "insert into" or ??
If somebody can help, would be great.
Thanks

 


 

Link to comment
Share on other sites

The "r" and the "s" are table aliases, not realy neccessary here (force of habit) but are useful if you have columns in different table with the same name.

Suppose reps and sales both had columns called "id"; you could then differentiate between them by either reps.id and sales.id or by using the aliases r.id and s.id, which is quicker to write.

Occasionally you may wish to reference the same table twice or more in a query in which case the alias is essential

EG

TABLE : people
------------------------------
id int primary key
name varchar
father_id int foreign key
mother_id int foreign key
------------------------------

SELECT p.id
     , p.name as person
     , f.name as father
     , m.name as mother
FROM people p
     JOIN people f ON p.father_id = f.id
     JOIN people m ON p.mother_id = m.id

 

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.