Page 1 of 1

tables with same field name

Posted: Wed Jul 04, 2012 8:24 pm
by jayson.ph
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.

Re: tables with same field name

Posted: Wed Jul 04, 2012 8:34 pm
by jayson.ph
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

Re: tables with same field name

Posted: Thu Jul 05, 2012 12:38 am
by Christopher
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

Re: tables with same field name[Solve]

Posted: Thu Jul 05, 2012 2:33 am
by jayson.ph
Thank 'Christopher' i gut it. thank..

Re: tables with same field name[SOLVE]

Posted: Thu Jul 05, 2012 10:34 pm
by jayson.ph
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

Posted: Thu Jul 05, 2012 11:57 pm
by jayson.ph
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)";

Re: tables with same field name[SOLVE]

Posted: Fri Jul 06, 2012 9:36 am
by Christopher
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.
You will get:

Code: Select all

array(
't1fa' => 'foo',
't2fa' => 'bar',
);