You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: INSTRUCTIONS.md
+26-22
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,10 @@
1
-
# The SELECT Statement
1
+
# SQL and PHP Query Builder Conversion Guide
2
2
3
-
## FROM Clause
3
+
This guide is designed to help AI systems translate SQL queries into PHP Query Builder syntax and vice versa, covering essential SQL clauses and concepts.
4
+
5
+
## The SELECT Statement
6
+
7
+
### FROM Clause
4
8
5
9
Consider the following SQL statement:
6
10
@@ -16,7 +20,7 @@ $db->select()
16
20
->from('p', 'products');
17
21
```
18
22
19
-
### Using an Alias in the FROM Clause:
23
+
####Using an Alias in the FROM Clause:
20
24
21
25
There are generally two ways to write this. In the syntax with two parameters, the first parameter is always the alias, and the second parameter is always the table name:
22
26
@@ -30,7 +34,7 @@ This is equivalent to
30
34
/* ... */ ->from('p', 'products');
31
35
```
32
36
33
-
### Using the FROM Clause Without an Alias:
37
+
####Using the FROM Clause Without an Alias:
34
38
35
39
If only one parameter is used, it will be interpreted as the table name:
36
40
@@ -44,7 +48,7 @@ This is equivalent to
44
48
/* ... */ ->from('products');
45
49
```
46
50
47
-
## Using Table Fields
51
+
###Using Table Fields
48
52
49
53
Translate table fields to match the following pattern:
50
54
@@ -87,9 +91,9 @@ $db->select()
87
91
88
92
Here’s the enhanced document with additional sections explaining the use of LEFT JOIN, RIGHT JOIN, INNER JOIN, WHERE, HAVING, ORDER BY, LIMIT, OFFSET, and subselects in SQL, along with corresponding examples in PHP Query Builder.
89
93
90
-
## JOIN Clauses
94
+
###JOIN Clauses
91
95
92
-
### INNER JOIN
96
+
####INNER JOIN
93
97
94
98
`INNER JOIN` returns rows when there is a match in both tables. Example SQL:
`LEFT JOIN` returns all rows from the left table, and matched rows from the right table. If there is no match, NULL values are returned for columns from the right table.
109
113
@@ -119,7 +123,7 @@ PHP Query Builder equivalent:
119
123
->joinLeft('t3', 'test3', 't3.test_id = t1.id')
120
124
```
121
125
122
-
### RIGHT JOIN
126
+
####RIGHT JOIN
123
127
124
128
`RIGHT JOIN` returns all rows from the right table, and matched rows from the left table. If there is no match, NULL values are returned for columns from the left table. Example SQL:
125
129
@@ -133,7 +137,7 @@ PHP Query Builder equivalent:
133
137
->joinRight('t4', 'test4', 't4.test_id = t1.id')
134
138
```
135
139
136
-
### Using Subselects in JOINs
140
+
####Using Subselects in JOINs
137
141
138
142
A subselect can be used as a virtual table in joins. Here’s an example with `RIGHT JOIN`:
139
143
@@ -154,7 +158,7 @@ $subSelect = function ($id) use ($mysql) {
The value can be a scalar value (including `null`) and can also be an array of values. The Query Builder will automatically translate value-arrays into an according `IN`-Clause.
172
176
173
-
## HAVING Clause
177
+
###HAVING Clause
174
178
175
179
The `HAVING` clause is used to filter records after aggregation. It typically applies to grouped results. Example SQL:
176
180
@@ -184,7 +188,7 @@ PHP Query Builder equivalent:
184
188
->having('customer_count > 10')
185
189
```
186
190
187
-
## ORDER BY Clause
191
+
###ORDER BY Clause
188
192
189
193
The ORDER BY clause is used to sort the result set by one or more columns. Example SQL:
190
194
@@ -199,7 +203,7 @@ PHP Query Builder equivalent:
199
203
->orderBy('t1.field2', 'DESC')
200
204
```
201
205
202
-
## LIMIT Clause
206
+
###LIMIT Clause
203
207
204
208
The LIMIT clause specifies the maximum number of records to return. Example SQL:
205
209
@@ -213,7 +217,7 @@ PHP Query Builder equivalent:
213
217
->limit(100)
214
218
```
215
219
216
-
## OFFSET Clause
220
+
###OFFSET Clause
217
221
218
222
The OFFSET clause is used in conjunction with LIMIT to skip a certain number of rows before beginning to return rows. Example SQL:
219
223
@@ -227,7 +231,7 @@ PHP Query Builder equivalent:
227
231
->offset(50)
228
232
```
229
233
230
-
## Using Subselects
234
+
###Using Subselects
231
235
232
236
Subselects (or subqueries) are queries nested within another query, often used to retrieve data for specific conditions.
0 commit comments