MYSQL from syntax with comma
from syntax with comma means inner join with no ON statement. Meaning it will return every matching pair for both tables. If one table A contains only 1 column and 1 value, meaning every row from other table B will be paired with this row, and returned, the value for table A for paried rows will be null.
If table A conatins no row, then nothing will be returned from this inner join.
Detailed explanation from stack over flow :
https://stackoverflow.com/questions/26465412/how-does-mysql-from-clause-work-with-multiple-table-names
Your query with the empty result set is this, elaborated for readability
SELECT ord.*
FROM orders AS ord, order_hotels AS oh
It is the old-timey comma-separated list of tables, syntax for this query
SELECT ord.*
FROM orders AS ord
INNER JOIN order_hotels AS oh
This query, an INNER JOIN without any ON clause, returns one row for each possible pairing of rows in orders and order_hotels. You have stated that order_hotels contains no rows. So, this query is dutifully returning every possible pairing, which is no rows.
MYSQL where with #s
where 1(means 1=1) or where 1 AND 4, or where 4 AND 5, means where has no effect, all rows will be returned.
where 0 means(0=0) or where 0 and 1. or where 1 and 0, means no rows will be returned.
stack over flow explanation
https://stackoverflow.com/questions/1983655/importance-of-where-1-in-mysql-queries
MYSQL find_in_set function
The FIND_IN_SET() function returns the position of a string within a list of strings.
Poistion starts at 1 instead of 0
https://www.w3schools.com/sql/trymysql.asp?filename=trysql_func_mysql_find_in_set
https://www.w3schools.com/sql/trymysql.asp?filename=trysql_func_mysql_find_in_set
If not exist, will return 0
https://www.w3schools.com/sql/trymysql.asp?filename=trysql_func_mysql_find_in_set2
will return empty if string is null
https://www.w3schools.com/sql/trymysql.asp?filename=trysql_func_mysql_find_in_set3
MYSQL length function
The LENGTH() function returns the length of a string (in bytes).
https://www.w3schools.com/sql/trymysql.asp?filename=trysql_func_mysql_length
SELECT LENGTH("SQL Tutorial") AS LengthOfString;
returns 12, 1 byte for each char(11), 1 byte for space
https://www.w3schools.com/sql/trymysql.asp?filename=trysql_func_mysql_length
MYSQL concat function
Add string together
https://www.w3schools.com/sql/func_mysql_concat.asp
SELECT CONCAT("SQL ", "Tutorial ", "is ", "fun!") AS ConcatenatedString;
No comments:
Post a Comment