-1
I have never done this, I need to create a QUERY for MYSQL to display data from two tables, a table of the male gender and another of the female gender. I know that the correct thing is to create a field to differentiate the gender, but the example below is only didactic, because what I need is for another data structure, where the example portrays well what I need to do.
tbl_masc | | id (int(11)) | name (varchar(50)) | surname (varchar(50)) | age (int(3)) | data_nasc (datetime())
tbl_fem | | id (int(11)) | name (varchar(50)) | surname (varchar(50)) | age (int(3)) | data_nasc (datetime())
I know tables relationship as follows:
<?php
$SQL = "SELECT
a.*,b.*,
(
SELECT
`cor`
FROM
`cabelo`
WHERE
`id_cor` = a.`cor_cabelo`
LIMIT
1
) AS `cabelo`
FROM
`tbl1` a
LEFT JOIN
`tbl2` b
ON
b.`id` = b.`id_pai`
WHERE
a.`status` = 'A'
ORDER BY
a.`nome`
ASC
LIMIT
12
;";
?>
The intention of the above query is to let you know that I know how to mount a query, perform queries and whatever is necessary within my limitation, because I’m not asking for help with something chewed, is that I really don’t know how to do. I need a north for that!
Do you want to create a loop in PHP or do a query that searches the data in the 2 tables? It was not clear the question.
– Ricardo BRGWeb
Sorry, I corrected
– ElvisP
I still don’t understand... you want to select the data from two different tables is that it? You can do this only with a select, without having to loop any... if you put part of your PHP code, maybe it is clearer...
– Ricardo BRGWeb
That’s right, QUERY SELECT for MYSQL rs
– ElvisP