This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 5 years ago.
I have db like this :
id, name, group.
(Group is a slug, that I can't know for my request)
So one group can have many name.
I want to sort by group with php/mysql.
I want get something like this :
$request = array( 'groupeOne = array ('name')', 'groupeTwo = array()' )
Something like this. I try to order by group but it doesn't work
You can use
order by
`group` (using backtics ..because group is a reserver word
select tid, name, `group`
from my_table
order by `group`
Related
This question already has answers here:
SELECT * EXCEPT
(15 answers)
Closed 1 year ago.
Suppose I have a table that contains "200" columns, how do I select all colons except a few, and the way I know is to select it manually:
"SELECT id, user, name, email, city... FROM table WHERE id = 1";
However my wish would be something like:
"SELECT * (exeto essas tabelas) FROM table WHERE id = 1";
The only way you can achieve that in MySQL is to use hidden columns (https://dev.mysql.com/doc/refman/8.0/en/invisible-columns.html).
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 6 years ago.
$sql= "SELECT name, content FROM {$dbpraefix}meta_global
UNION SELECT name, content FROM {$dbpraefix}meta_local
LEFT JOIN {$dbpraefix}pages ON {$dbpraefix}pages.id={$dbpraefix}meta_local.page
WHERE {$dbpraefix}pages.alias = $_GET['include']";
Hello Everyone. whats wrong with the last part of my code.
WHERE {$dbpraefix}pages.alias = $_GET['include']"
my page doesnt work. but if i throw the last part, it works well.
this is a part of my "build your own CMS" projekt.
thanks for your answers.
Try this : add single quote
$sql= "SELECT name, content FROM {$dbpraefix}meta_global
UNION SELECT name, content FROM {$dbpraefix}meta_local
LEFT JOIN {$dbpraefix}pages ON {$dbpraefix}pages.id={$dbpraefix}meta_local.page
WHERE {$dbpraefix}pages.alias = '".$_GET['include']."'";
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 6 years ago.
I use below php code to generate a random id number
md5(uniqid(rand(), true)
the type of string it generate is something like this
9a423553ce53c4d7a6199fa9254bfdc5
I use that as an ID in Mysql table then I do a standard select query
SELECT * FROM table WHERE id = 9a423553ce53c4d7a6199fa9254bfdc5
I get this error
Unknown column '9a423553ce53c4d7a6199fa9254bfdc5' in 'where clause'
if I just change the id to a simple number like 1 it works.
Why is this?
Have you tried encapsulating that in quotes? In your query id = 9a423553ce53c4d7a6199fa9254bfdc5 You can compare two columns like id = other_id .. MySQL needs to know how to handle your query.
For clarification, should be: SELECT * FROM table WHERE id = '9a423553ce53c4d7a6199fa9254bfdc5';
This question already has answers here:
Query with multiple values in a column
(4 answers)
MySQL search in comma list [duplicate]
(5 answers)
Closed 7 years ago.
I'm wanting to create a sql select statement that will grab rows if a given value is in a comma separated list in one of the columns of the database table.
Example Table...
id | courses
1 | 5, 8, 15, 19
I want to do something like this
$course_num = 5;
$sql = "SELECT * FROM courses WHERE $course_num IS IN courses";
1.) I don't think the "IS IN courses" part is legit. How can I do this?
2.) For my code above, I would want to return the row because of the "5" in courses, not because of the "15". So, if $course_num = 9 no rows should be returned.
Thanks for your help.
By adding comma in searched occurrence
SELECT *
FROM courses
WHERE concat(', ',course,',') like '%, 5,%'
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 7 years ago.
I'm converting all MySQL to MySQLi pages. I need to select all rows where a column starts with a letter.
On MySql If I want all rows starting with P, I used to add % to P, so I'll search all entries LIKE P%, but it's not working on MySQLi
If $type = P%
$result = $mysqli->query("SELECT * FROM my_table WHERE column LIKE $type");
I get no results.
I appreciate any help you can provide.
Try putting quotes around the variable in the query so that it looks like this :
$result = $mysqli->query("SELECT * FROM my_table WHERE column LIKE '$type'");
This will probably solve the problem.