LoginSignup
2
2

More than 5 years have passed since last update.

ActiveRecordをsqlで理解する。

Last updated at Posted at 2016-02-26
SELECT  `users`.* FROM `users` WHERE `users`.`email` = 'test@email.com'  ORDER BY `users`.`id` ASC LIMIT 1

ORDER BY

ORDER BY 'users','id'だったら
まずusersでソートしてから、idでソートする。

ということになる。

並べる順番は

ASCで昇順

1
2
3
4

DECで降順

4
3
2
1

 行数を制限

LIMIT 1

LIMITはデータの先頭から順番に取得する。

WHERE

ある列の文字列の値がこの文字列の値と等しいのような条件しきになる。

WHEREusers.email= 'test@email.com'
userテーブルのemailと'test@email.com'を検索する。

FROM

FROM `users` 

FROM <テーブル名>

SELECT

SELECT <列名>,<列名>....

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2