Welcome Guest, Not a member yet? Register   Sign In
How to write this SQL statement in Active Record
#4

[eluser]WanWizard[/eluser]
Read the query, and then read it again. There is no join in this query. If you don't see the error, may I suggest to read up on designing queries?
Code:
mysql> use test;
Database changed

mysql> select * from users;
+---------+----+--------+
| user_id | id | name   |
+---------+----+--------+
|       1 |  1 | user 1 |
|       2 |  2 | user 2 |
+---------+----+--------+
2 rows in set (0.00 sec)

mysql> select * from example_tbl;
+---------+--------+
| slogan  | brief  |
+---------+--------+
| slogan1 | brief1 |
| slogan2 | brief2 |
+---------+--------+
2 rows in set (0.00 sec)

mysql> SELECT a.slogan, a.brief, u.id, u.name FROM example_tbl AS a, users AS u WHERE u.user_id =1;
+---------+--------+----+--------+
| slogan  | brief  | id | name   |
+---------+--------+----+--------+
| slogan1 | brief1 |  1 | user 1 |
| slogan2 | brief2 |  1 | user 1 |
+---------+--------+----+--------+
2 rows in set (0.00 sec)
Urhm... I really see 2 rows in the result set here...


Messages In This Thread
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 08:11 AM
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 08:36 AM
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 09:10 AM
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 09:25 AM
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 10:27 AM
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 11:03 AM
How to write this SQL statement in Active Record - by El Forum - 06-14-2010, 12:12 PM
How to write this SQL statement in Active Record - by El Forum - 06-14-2010, 05:36 PM
How to write this SQL statement in Active Record - by El Forum - 06-14-2010, 10:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB