Skip to content

Latest commit

 

History

History
34 lines (22 loc) · 907 Bytes

from.md

File metadata and controls

34 lines (22 loc) · 907 Bytes

From

The Yiisoft\Db\Query\Query::from() method specifies the FROM fragment of a SQL statement.

For example, the following code will select all columns from the user table.

$query->from('{{%user}}');

The equivalent SQL is:

SELECT * FROM `user`

You can specify the table(s) to select as either a string or an array. The table names may contain schema prefixes and/or table aliases, like you do when writing raw SQL statements.

$query->from(['{{public.%user}} u', '{{public.%post}} p']);

// equal to:

$query->from('{{public.%user}} u, {{public.%post}} p');

Tip: Prefer the array format since it leaves less space for mistakes and is cleaner overall.

If you're using the array format, you can also specify the table aliases in array keys, like the following.

$query->from(['u' => '{{public.%user}}', 'p' => '{{public.%post}}']);