Jump to content

[SOLVED] Syntax Question


Lambneck

Recommended Posts

What is the proper way to write this select statement?

I'm trying to get the column "submission id"

from a form or table (table2) inside a table (table1).

 

I tried the following but doesn't work...

 

$sql = "SELECT submission id FROM table1 WHERE table2";

Link to comment
Share on other sites

I think this is what you are looking for (pulled from my book, see sig):

 

SELECT * FROM table1 INNER JOIN table2 on table1.id = table2.id

// Returns all columns in table1 and table2 where the id matches

// on both tables (any rows in table1 without an id that matches

// is excluded from the resulting combined results)

 

SELECT table1.* FROM table1 INNER JOIN table2 on table1.id = table2.id

// Same as above, except only columns from table1 are included

 

SELECT table1.id FROM table1 INNER JOIN table2 on table1.id = table2.id

// Same as above, except only the id column from table1 is included

 

SELECT table.id AS tableid FROM table

// Give an alias to the column using AS (so id will result as tableid)

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.