Jump to content


This topic is now archived and is closed to further replies.


Getting data from more than one table

Recommended Posts

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??

Share this post

Link to post
Share on other sites
What are your table names? basicaly looks like u need

SELECT * FROM table1, table2 WHERE table1.ID = table2.id

If 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

Share this post

Link to post
Share on other sites
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] s
INNER [color=green]JOIN[/color] order_item i
on s.stockID [color=orange]=[/color] i.stockID
[color=green]WHERE[/color] i.orderiD [color=orange]=[/color] [color=red]'$orderID'[/color]

this will select all from both tables

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.