NOTICE: If you are using Fabrik and update to Joomla 3.10, you will need to update to Fabrik 3.10. And, if you are using Fabrik, do not upgrade to Joomla 4, we do not have a supported version ready for release. More information on a release date coming soon. Also, please note that Fabrik 3.10 will not install on any Joomla sites less than 3.8.Dismiss Notice
What is a Database?
This wiki entry is designed to explain the basics of SQL databases for those who have not come across them before.
Database Tables (top)The basic building block of an SQL database is a Table.
A database table is structured like a spreadsheet, with column names (these are the elements in your form) and rows (these are the individual records submitted via your form).
Primary Keys (top)Each table should have its own 'Primary Key', a column (or sometimes a set of columns) for which every row of the table must have a unique value. Often you use a unique ID number for each record, and SQL provides an automatic incrementing number field, which Fabrik creates by default for each List using an internalID element.
Table Joins (top)As your operation increases in size or complexity, you will find that you will want to cross reference data from different tables, and that there are columns that repeat in separate database tables. When this happens, the solution you will come across is given the term 'database join' - this is both an action (ie the searching for sets of related data) and a result (ie the data that is then outputted).
Good explanations of database joins can be found at:
Fabrik Parameters), if we have created other forms associated with other database tables that also have their own 'userid' element, then the common element or column in both tables is 'userid'.
So you might JOIN a customer and an order table as follows:
Code (SQL):SELECT Customer.Name, Orders.Amount
ON Customer.ID = Orders.Customer_ID;
- LEFT JOIN
- RIGHT JOIN
- OUTER JOIN
JOIN (top)A plain 'JOIN' (also known as an 'INNER JOIN') will return rows only when there are rows in both tables with matching join fields. So in the above example, you would get records only for customers who have at least one order, and only for orders which are associated with a customer.
Customers with multiple orders will have multiple rows. Customers with no orders, and orders without an associated customer will not appear in the results.
LEFT JOIN (top)A 'LEFT JOIN' (also known as a 'LEFT OUTER JOIN') returns all rows in the first table, together with any matching rows in the second table. In the above example, this would return all customers, and any orders associated with these customers.
Customers with one or more orders will appear as before. But this time, customers with no orders will have a single row and the order columns will be blank. Orders not associated with a customer will still not be shown.
RIGHT JOIN (top)A 'RIGHT JOIN' (also known as a 'RIGHT OUTER JOIN') returns all rows in the second table, together with any matching rows in the first table. In the above example, this would return all orders, and any customers associated with these orders.
Customers with one or more orders will appear as before. But this time, orders not associated with a customer will have a single row and the customer columns will be blank. Customers without any orders will not be shown.
OUTER JOIN (top)
An 'OUTER JOIN' (also known as a 'FULL JOIN') returns all rows in the both tables. In the above example, this would return all customers and all orders, regardless of whether a customer has any orders or whether an order is associated with a customer.
Customers with one or more orders will appear as before. Customers with no orders will have a single row and the order columns will be blank. Orders not associated with a customer will have a single row and the customer columns will be blank.
See also ... (top)