Jump to content

Explain Query


ueon

Recommended Posts

I hired someone to do a project, and I need to alter his query a bit but have no idea what it says :

 

$query = "select a.*,b.Username,b.EmailAddress,b.UserID from status a inner join users b on(a.email=b.EmailAddress)  where a.email in($searchuser) order by id desc ";

 

 

Link to comment
Share on other sites

query selects every field from table a.. which is what a.* means

the fields Username,EmailAddress,UserID from table b..

now the programmer aliases table status to be "a" and users to be "b", for a shorter query..

the tables are joined on the condition that the email field from the "status" table equals the Emailaddress field from table "users"

now the main query has a WHERE clause here it will grab rows where the value from field "email" from table "status" is in the array $searchuser..

it orders the results by id descending..

Link to comment
Share on other sites

the ON is used in JOIN queries... and specifies how the two queries are joined, what the conditions need to be in order for the tables to join.. IN is a MYSQL function that searches an array of values for the specified value... documentation and examples can be found at these two links

 

http://dev.mysql.com/doc/refman/5.0/en/join.html

 

http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_in

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.