OriginalSunny Posted March 15, 2006 Share Posted March 15, 2006 Hi, I am having a few problems with getting the data i want from my tables. I have used the code below which works fine:[i]$sql_ord = "[b]SELECT s.* FROM stock s[/b] INNER JOIN order_item i on s.stockID = i.stockID WHERE i.orderiD = '$orderID'";[/i]However when i change the bit highlighted in bold to:[i][b]SELECT s.* FROM stock s and i.* FROM order_item i, i.* FROM stock[/b][/i]It comes up with an error. I am using an array to ouput the data i need from the tables but as i need to get data from both tables so i can output the data from both tables, what do i do? I am sure there must be a command to select the data from 2 tables??Thanks. Link to comment https://forums.phpfreaks.com/topic/5036-getting-data-from-more-than-one-table/ Share on other sites More sharing options...
shocker-z Posted March 15, 2006 Share Posted March 15, 2006 What are your table names? basicaly looks like u needSELECT * FROM table1, table2 WHERE table1.ID = table2.idIf that helps you in how you select * from both tables?I'm a bit confused with your code tho so not sure if thats going to help properly Link to comment https://forums.phpfreaks.com/topic/5036-getting-data-from-more-than-one-table/#findComment-17806 Share on other sites More sharing options...
obsidian Posted March 15, 2006 Share Posted March 15, 2006 try the following:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * [color=green]FROM[/color] [color=orange]stock[/color] sINNER [color=green]JOIN[/color] order_item ion s.stockID [color=orange]=[/color] i.stockID[color=green]WHERE[/color] i.orderiD [color=orange]=[/color] [color=red]'$orderID'[/color][!--sql2--][/div][!--sql3--]this will select all from both tables Link to comment https://forums.phpfreaks.com/topic/5036-getting-data-from-more-than-one-table/#findComment-17810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.