Lambneck Posted April 12, 2008 Share Posted April 12, 2008 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"; Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted April 12, 2008 Share Posted April 12, 2008 Give us your table structures. Also, which field ties table1 and table2 together? Quote Link to comment Share on other sites More sharing options...
ucffool Posted April 13, 2008 Share Posted April 13, 2008 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.