[wd_asp elements=’search’ ratio=’100%’ id=1]

Join – Get data from two tables using one query

17th March 2014

MySql

mysql codehaven category

$query = "SELECT * FROM

(SELECT campaign from targets where client='".$pc_id."' AND enabled !='disabled'

UNION

SELECT groupname AS campaign FROM clientcombine WHERE client='$pc_id')

AS campaign";

Then just collect CAMPAIGN as your row.


$query = "SELECT * FROM
(SELECT targetcpa AS targetcpa,client FROM targets WHERE client='Dog'
UNION
SELECT campaign,client from mydata where date="2014-04-07" AND client='Dog')";

AS campaign
This above code will combine two sets of data(one from each table) into one….

Or this

$result = mysql_query("SELECT * FROM tasks
JOIN residents
ON residents.id = tasks.forwho
WHERE tasks.id = '$taskid' ");