Hi all,
i have, a 3 tables with different data inside but same field name. and now it is possible to join 3 table to show up in webpage. if it is possible what should sql statement i use.
tables with same field name
Moderator: General Moderators
tables with same field name
Last edited by jayson.ph on Thu Jul 05, 2012 10:35 pm, edited 2 times in total.
Re: tables with same field name
ex.
table1
field-a = ibm
field-b = asus
field-c = apple
table2
field-a = samsung
field-b = lenovo
field-c = hp
page->
field-a ==========field-b=========field-c
ibm=============asus===========apple
samsung=========lenovo========= hp
table1
field-a = ibm
field-b = asus
field-c = apple
table2
field-a = samsung
field-b = lenovo
field-c = hp
page->
field-a ==========field-b=========field-c
ibm=============asus===========apple
samsung=========lenovo========= hp
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: tables with same field name
Use the table names to specify the field names and use AS to rename fields.
SELECT table1.field-a AS t1fa, table2.field-a AS t2fa FROM table1 JOIN table2 ON table1.field-a=table2.field-a
SELECT table1.field-a AS t1fa, table2.field-a AS t2fa FROM table1 JOIN table2 ON table1.field-a=table2.field-a
(#10850)
Re: tables with same field name[Solve]
Thank 'Christopher' i gut it. thank..
Re: tables with same field name[SOLVE]
Hi all, another question, this situation is i use array to show up the following data. i wondering since i have two same name field. what should the name i put inside the array. between two table1.field-a AS t1fa, table2.field-a AS t2fa.
Re: tables with same field name
Please help to construct:
Code: Select all
SELECT tbl_update_request.id AS myid,
tbl_update_request.uid AS myuid,
tbl_update_request.cat_name AS mycat_name,
tbl_update_request.product_name AS myproduct_name,
tbl_update_request.product_model AS myproduct_model,
tbl_update_request.product_desc AS myproduct_desc,
tbl_update_request.re_qty AS myre_qty,
tbl_update_request.dt_nwo AS mydt_nwo,
tbl_update_request.commnt AS mycommnt,
tbl_update_request.rec_on AS myrec_on,
tbl_update_request.return_on AS myreturn_on,
tbl_update_request.balancs AS mybalancs,
tbl_update_request.sold AS mysold,
tbl_update_request.tbl_brnch_name AS mytbl_brnch_name
FROM (tbl_update_request.uid,
tbl_update_request.cat_name,
tbl_update_request.product_name,
tbl_update_request.product_model,
tbl_update_request.product_desc,
tbl_update_request.re_qty,
tbl_update_request.dt_nwo,
tbl_update_request.commnt,
tbl_update_request.rec_on,
tbl_update_request.return_on,
tbl_update_request.balancs,
tbl_update_request.sold,
tbl_update_request.tbl_brnch_name FROM tbl_update_request UNION ALL SELECT
tbl_brn_requst.id,
tbl_brn_requst.cat_name,
tbl_brn_requst.product_name,
tbl_brn_requst.product_model,
tbl_brn_requst.rec_on,
tbl_brn_requst.return_on,
tbl_brn_requst.balancs,
tbl_brn_requst.sold,
tbl_brn_requst.re_qty,
tbl_brn_requst.dt_nwo,
tbl_brn_requst.commnt FROM tbl_brn_requst UNION ALL SELECT tbl_user.uid,
tbl_user.tbl_brnch_name FROM tbl_user)";- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: tables with same field name[SOLVE]
You will get:jayson.ph wrote:Hi all, another question, this situation is i use array to show up the following data. i wondering since i have two same name field. what should the name i put inside the array. between two table1.field-a AS t1fa, table2.field-a AS t2fa.
Code: Select all
array(
't1fa' => 'foo',
't2fa' => 'bar',
);(#10850)