Jump to content

Getting data from more than one table


OriginalSunny

Recommended Posts

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
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
Link to comment
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]
[!--sql2--][/div][!--sql3--]

this will select all from both tables
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.