- - 2nd table
||03-16-2009 04:21 PM
Is it possible to make an query like:
Table 1: id;nickname(unique);rights
Table 2: id;email;nickname
Now I want to select the email where rights equals to 3.
Is it possible to write that in one single query?
(The tables cannot be put together in one because thats an excisting system...)
||03-16-2009 05:36 PM
You want to look up what's called a 'join', ie; http://www.w3schools.com/Sql/sql_join.asp
SELECT t1.id, t1.nickname, t2.email FROM table1 AS t1 INNER JOIN table2 AS t2 ON t1.id=t2.id WHERE t1.rights = 3
SELECT t1.id, t1.nickname, t2.email
// Select the id, nickname and email data. We don't need to select the rights, we already know
// everybody selected from this query should be equal to 3
FROM table1 AS t1
// The primary table we're operating on
INNER JOIN table2 AS t2
// We use an inner join because we only want to return records where there is at least one
// row in both tables that match the join condition.
// The join condition
WHERE t1.rights = 3
// Where the rights column of table one is equal to 3
I haven't programmed in nearly 6 months so I could be a little rusty but I'm fairly certain this is what you're in the market for.
||03-17-2009 06:29 AM
Yeah, that should do it. THX alot :-)
|All times are GMT. The time now is 06:42 AM.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0