homepage Welcome to WebmasterWorld Guest from 54.167.173.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
select from multiple tables - same field name
php/mysql
knighty




msg:1290502
 2:35 pm on Jan 10, 2003 (gmt 0)

I have a number of tables ie, sales, number of customers, refunds.

each table is split up by months jan, feb, march etc.

I want to display all the months and then each table on a row, so along the top you have the months then below each month would be the appropiate figure from each table.

can i use something like select * from sales, customers where storeid=12345

then print out $jan, $feb, $March

I'm struggling on how to output the results cos there are going to be more than one field called january - how do get sales/january and customers/january

TIA

 

dingman




msg:1290503
 3:14 pm on Jan 10, 2003 (gmt 0)

Are you looking for something like "select S.january, C.january, etc from Sales as S [some kind of] join Customers as C [using field] where storeid=1234"?

That's a very rough outline, but when you need to disambiguate filed names in a select on multiple tables, the 'as' keyword is your friend.

knighty




msg:1290504
 3:29 pm on Jan 10, 2003 (gmt 0)

I don't know I just want to end up with ...

SALES JAN - 35%
SALES FEB - 50%
CUSTOMERS JAN - 456
CUSTOMERS FEB - 654

where sales and customers are the tables, Jan and feb are field names and numbers are the values of the fields.

I know I can just do

select * from sales where storeID=666
select * from custoers where storeID=666

but I have a lot of tables and wondered if I can do it all in one go?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved