$citys = mysqli_query($connect, "SELECT * FROM `city`");
$citys = mysqli_fetch_all($citys);
echo '<select name="magaz">' . PHP_EOL;
foreach ($citys as $city) {
echo '<option value=' . $city[0] . '>' . $city[1] . '</option>' . PHP_EOL;
}
echo '</select>' . PHP_EOL;
select *
from table1
left join table2 on table1.code = table2.id1
where table1.code = 1;
SELECT *
FROM users
WHERE name = 'Мария' AND city = 'Саратов';
SELECT *
FROM users
WHERE name IN ('Саратов', 'Мария') AND city IN ('Саратов', 'Мария');
-- Используя WHERE NOT EXISTS
SELECT *
FROM QEEN
WHERE NOT EXISTS (
SELECT ID FROM QEEN REVERSE_QEEN WHERE REVERSE_QEEN.A = QEEN.B AND REVERSE_QEEN.B = QEEN.A
);
-- Используя LEFT JOIN
SELECT QEEN.*
FROM QEEN
LEFT JOIN QEEN REVERSE_QEEN ON REVERSE_QEEN.A = QEEN.B AND REVERSE_QEEN.B = QEEN.A
WHERE REVERSE_QEEN.ID IS NULL;
-- Просто извращение, но тоже должно работать :)
WITH ALL_QEEN AS (
SELECT ID, A, B, 1 T FROM QEEN
UNION ALL
SELECT ID, B, A, 2 T FROM QEEN
) SELECT
MIN(ID) ID, A, B
FROM ALL_QEEN
GROUP BY A, B
HAVING COUNT(*) = 1 AND MIN(T) = 1;
$query = "SELECT * FROM `mytable` ";
$result = $mysqli->query($query);
$rows = $result->fetch_all(MYSQLI_ASSOC);
$MyListArray = [];
while ($row = $queryResult->fetch_assoc()) {
$MyListArray[] = $row;
};
SELECT * FROM `category`
ORDER BY COALESCE(`orderNum`, `name`)
SELECT * FROM `category`
ORDER BY `orderNum` IS NULL, `name`;
select replace(
'format|MP3||duration|01:42:46||year|2020||tracks|0||size|238 MB||torrent-mp3|[attachment=190:miami-cyber-nights-vol-1-2020.torrent]',
'|tracks|0|',
''
) as res;
+===========================================================================================================================+
| res |
+===========================================================================================================================+
| format|MP3||duration|01:42:46||year|2020||size|238 MB||torrent-mp3|[attachment=190:miami-cyber-nights-vol-1-2020.torrent] |
+---------------------------------------------------------------------------------------------------------------------------+
DELETE PeopleFruit.*
FROM PeopleFruit
LEFT JOIN (SELECT MAX(Id) Id FROM PeopleFruit) MaxId USING(Id)
WHERE MaxId.Id IS NULL;
function cmp_function_desc($a, $b){
return ($b['status'] <=> $a['status']);
}
uasort($banks['bank'], 'cmp_function_desc');
print_r($banks);
SELECT things.id_thing, things.data, GROUP_CONCAT(note) notes
FROM things
LEFT JOIN notes USING(id_thing)
GROUP BY things.id_thing, things.data
;
SELECT * FROM orders WHERE order_date BETWEEN CURRENT_DATE() AND NOW();
SELECT * FROM orders WHERE order_date BETWEEN '2021-12-15 00:00:00' AND '2021-12-15 23:59:59' ;
CREATE TABLE orders (
id int unsigned primary key auto_increment,
amount decimal(9,2),
created_at datetime default NOW()
);
INSERT INTO orders (amount) VALUES (999.99);
UPDATE products
JOIN (
SELECT PRODUCT_ID, JSON_ARRAYAGG(FILENAME) IMAGES
FROM images
GROUP BY PRODUCT_ID
) images ON images.PRODUCT_ID = products.ID
SET NEW_IMAGE = IMAGES;
SELECT concat(
JSON_UNQUOTE(json_extract(additional,'$.surname')),
JSON_UNQUOTE(json_extract(additional,'$.firsname')),
JSON_UNQUOTE(json_extract(additional,'$.lastname'))
) fullname
FROM `user_attributes`
;