View Full Version : query two tables
jackavin
05-28-2008, 08:28 AM
hi i have product A and B
A have
Aid
price
date
isbn
B have
Aid
price
date
album
i want to select them in one place i want just id,price and date
how can i query this!!??? thank you
Does this help you?
$query ="SELECT table1.field1, table2.field2 FROM table1, table2 WHERE table1.field1=table2.field2";
Red: Field in table1.
Navy: Field in table2.
LightGray: Table1.
DarkGray: Table2.
You can get a bit more info on that here: http://www.w3schools.com/sql/sql_join.asp
I hope this helps,
Nile
jackavin
05-28-2008, 01:06 PM
I'm sorry dude but table 1 and table 2 it doesn't have any relationship
ok table 1 is Book product and table 2 is cd product right and i want to view it at once in same list i build and the information that 2 table have the is price and title for example
so if i list it all when i click it it will go to product's page so that's mean book_id and cd_id is not the same right? do i miss anyhting
Sorry, I didn't understand that. Could you please rephrase it?
jackavin
05-29-2008, 01:26 AM
i have
table of product A
- Aid
- Price
- Adetail
table of product B
- Bid
- Price
- Bdetail
2 of these table r not have any relationship
how can i view this 2 tables in one query
how can i do that???
boogyman
05-29-2008, 12:34 PM
SELECT f1, f2 FROM t1 WHERE f1='foo' UNION(SELECT f3, f4 FROM t2 WHERE f3='foo')
http://dev.mysql.com/doc/refman/5.0/en/union.html
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.