how to select mysql query with foreign language?
You should try one of these:
1.) using mysql_set_charset('utf8', $dbconn);
instead of mysql_query() as shown in http://php.net/manual/en/function.mysql-set-charset.php
2.) use query("set names utf8");
as suggested in SET NAMES utf8 in MySQL?
how to select foreign language on MySQL
Well, it's obviously not going to translate anything for you. But if your columns support UTF, and the record exists, it will be found.
Mysql queries in other languages
SQL is in English, in fact it was initially called SEQUEL (Structured English QUEry Language) https://en.wikipedia.org/wiki/SQL
So do not worry about translating the queries, as they do not need to be translated into any language.
MySQL SELECT where common foreign key among many
You want to move the conditions to the having
clause:
SELECT s.settingID, s.setting_name
FROM tbl_neighbourhood n JOIN
tbl_setting s
ON s.settingID = n.settingID_fk
GROUP BY s.settingID, s.setting_name
HAVING sum(n.villageID_fk = 1) > 0 and
sum(n.villageID_fk = 2) > 0;
Each conditions counts the number of rows that match one of the villages. These guarantee that both are present.
You can also write this as:
SELECT s.settingID, s.setting_name
FROM tbl_neighbourhood n JOIN
tbl_setting s
ON s.settingID = n.settingID_fk
WHERE n.villageID_fk in (1, 2)
GROUP BY s.settingID, s.setting_name
HAVING count(distinct n.villageID_fk) = 2;
How can I query using a foreign key in MySQL?
SELECT u.*, s.*
FROM users u
inner join statuses s on u.status_id = s.id
WHERE u.status_id = 2
how to select more than one foreign key in a mysql query
You need to have each in a sub-select like below:
INSERT INTO table0 (integerVar1, integerVar2, booleanVar1)
SELECT (SELECT int1 FROM table1 WHERE aString = 'something'),
(SELECT int2 FROM table2 WHERE bString = 'otherthing'),
0;
However, keep in mind that if you have more than one value returned by the sub-select, it will not work.
This will be safer to use:
INSERT INTO table0 (integerVar1, integerVar2, booleanVar1)
SELECT (SELECT int1 FROM table1 WHERE aString = 'something' LIMIT 1),
(SELECT int2 FROM table2 WHERE bString = 'otherthing' LIMIT 1),
0;
Use ORDER BY clause on foreign language field
maybe you want to use backtick instead of single quote
SELECT *
FROM countries
ORDER BY `name_czech`
SQL-Query for a table with a foreign-key-field that references other foreign-key-fields
This query would work:
SELECT w.ID, worker, c.name AS `combined-Name`, d.department, l.department as
location FROM workers w
LEFT JOIN combined c ON c.ID = w.combined
LEFT JOIN helper h ON h.ID = c.helper
LEFT JOIN departments d ON d.ID = h.department
LEFT JOIN location l ON l.ID = h.location
GROUP BY w.ID
I used the AS
keyword to set the names to your preferred output.
This was tested locally using the provided structures and data.
It's basically 4 simple left joins, and then instead of selecting the ID's I select the name columns of the foreign tables.
The alias on c.name
is quoted because we need to escape the special character -
Related Topics
PHP Mail() Works from Command Line But Not Apache
Find All Hrefs in Page and Replace with Link Maintaining Previous Link - PHP
Client Side VS Server Side Basics
More Efficient Hierarchy System
What Is the ASP.NET Equivalent to PHP's Echo
PHP Date - Get Name of the Months in Local Language
Is $_Server['Http_Referer'] Safe
How to Disable Adding Properties into a Class from an Instance of the Class
Timestamps of Start and End of Month
Passing Variable from Controller to View in Codeigniter
How to Prevent Self Closing Tag in PHP Simplexml
Pull Random Line from Txt File as String
Get/Set Dpi with PHP Gd/Imagick
Cookies Not Working on Different Pages
Undefined Offset When Using PHP Explode()
Pdo Cannot Execute Queries While Other Unbuffered Queries Are Active
A Method of Selecting Random Characters from Given String
Displaying Blob Image from MySQL Database into Dynamic Div in HTML