Jump to content

find data from another table


adv

Recommended Posts

i have a column  `full_name` and another one named `type`

and i have  a column `client_name`  in table `data`

 

i want to search the `full_name` with the selected `type` and match in the column `clien_name` in the table `data`

and show only the ones that are in both tables

Link to comment
Share on other sites

They're just shorthand table aliases, so you say I want to reference table as t by "SELECT field FROM table t"

 

 

and the t. and d. are specifying which table the field belongs to, you need to do this when you make a mysql join because say if table1 has a field named id, and table2 also has a field named id, and I select id in a query where I join the result set from each table, it doesn't know which table's id field I want to select.

 

 

You could write that query like,

 

 

SELECT table.fullname FROM table
   INNER JOIN data ON ( table.full_name = data.client_name )
   WHERE table.type = '$type'

 

 

Thats saying

SELECT {the fullname field from the table "table"
   INNER JOIN {the data table} IF {full_name from table "table" is equal to client_name from table "data"}
   WHERE {type field from table "table" is equal to $type

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.