3

On https://docs.joomla.org/SQL_form_field_type it talks about using the SQL fields.

I'm wondering what sql_select="e.*" does.

I know that the star is a wildcard for everything. I'm just not sure what the e does (my first guess would be escape).

Can anyone fill me in?

Here is the full code:

<field
    name="example_group" 
    type="sql" 
    label="COM_EXAMPLE_GROUP" 
    sql_select="e.*" 
    sql_from="#__example AS e" 
    sql_group="name" 
    sql_order="e.id ASC" 
    key_field="id"
    value_field="name" 
    />
5

I guess the example you are talking about is this: "SELECT e.* FROM #__example AS e GROUP BY name ORDER e.id ASC"

Ths basically mean select everything from the table #__example (which has an alias name in the query of e) and group by name and order by id in ascending order.

if you didn't use AS e in the query you had to write the query as follows:

SELECT * from #__example GROUP BY ...

using AS e helps you save few characters to write when you do more complicated queries with a lot of joins etc.

You can check this resource for more beginner information on mysql: https://www.thegeekstuff.com/2013/09/mysql-select-command/

3

When you are only referencing one table in your query, there is no need to explicitly reference the table when writing columns. Also, the default order direction for sql is ASC.

So your syntax could be simplified to:

<field
name="example_group" 
type="sql" 
label="COM_EXAMPLE_GROUP" 
sql_select="id, name" 
sql_from="#__example" 
sql_group="name" 
sql_order="id" 
key_field="id"
value_field="name" 
/>

No table alias, no excess table references, no sorting direction -- sql will behave as intended by default.

I can only imagine that the docs page is being verbose for developers that may try more complicated queries or for developers that don't fully grasp how sql queries work by default.

As a matter of best practice, when you know the column(s) that you wish to extract data from, you should explicitly name the column(s) in the select clause. This way your coding intent is clear and your database doesn't need to work harder than necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.