Couchbase select reserved keyword named column - couchbase

In my couchbase query I am receiving error because "Path" is a reserved keyword.
select RawUrl, Path from couchbaseSample order by CreateTimeUtc desc
[{"code":3000,"msg":"syntax error - at Path"}
I tried using [Path] but did not work.
How can I fix this problem?

You can escape reserved words using back ticks.
select RawUrl, `Path` from couchbaseSample order by CreateTimeUtc desc

Related

The mysql problems(select * from my table)

I want to get a column from my table, but something wrong.
enter image description here
enter image description here
This problem is strange, I select * from order(a table of my database), but I cannot do that, I don't know where is wrong.
order is a reserved keyword in MySql where it is generally used to order output with reference to particular coloumn.
General logic of any coding or database structure is to avoid reserved keywords by that particular coding language or databases.
check the following link for reserved keywords in mysql
https://dev.mysql.com/doc/refman/5.5/en/keywords.html
In your case to resolve the issue , simply use back tick (" ` ") for the word order i.e.
select * from `order`
order is a reserved word in SQL. You will need to escape such a table name in your SQL:
SELECT * FROM `order`;
But it would be better would be to not use that as a table name.
Change the name of the table order or use `` before and after it so the code will be:
SELECT * FROM `order`;

ORDER BY doesn't sort alphabetically

I use the following MySQL query to get results, sorted alphabetically by name:
SELECT * FROM `client` WHERE CONCAT(name, ', ', firstname) LIKE "%ti%" ORDER BY name
In some way the results get sorted, so the ORDER BY works. Unfortunately it works not as expected. The above query gives the following order for example:
Kostic (31)
Hatscher (30)
Why is Kostic listed first? Prove me wrong, but K comes after H in the alphabet... (If it helps - the name field is type of varchar.)
It shouldn't be possible for K to come before H with ORDER BY name. Maybe a blank or even some unprintable character in front?
Test:
Do you get 'Kostic (31)' when you add AND name like 'K%'?
Do you get 'Hatscher (30)' when you add AND name like 'H%' instead?
I know ASC is the default when not specified in the ORDER BY but have you tried putting ASC after.. ORDER BY Name ASC. It's worth a shot

How do I select columns which has a dot in their column names

I am trying to select a record which clearly exists, but my SQL query does not bring it up. Any idea how to get this working?
SELECT * FROM Users WHERE 'local.email'='burgundy#email.com' LIMIT 1
The issue is that you're using single quotes ( ' ) around your column name, rather than using backticks ( ` ).
Try using this instead:
SELECT *
FROM Users
WHERE `local.email` = 'burgundy#email.com'
LIMIT 1
Like Crocodile said, anything that is a SQL variable like a table name or column name can also be surrounded by `` Back ticks (hold shift and hit ~). This tells SQL to look at them as literals.

mysql won't order by INT

I have set up a table with a column called order. I made sure it is set as INT. I can't seem to get the results to list in order. I currently have 5 rows with numbers 1-5 in a random order in those rows. However, I can't get those rows to go in order. Maybe I am doing this completely wrong, as I am new to MySql. Here is my query
SELECT * FROM faq ORDER BY 'order'
You should use the back-tick, not the quote:
SELECT * FROM faq ORDER BY `order`
You need to use backticks in mysql, not quotes.
SELECT * FROM faq ORDER BY `order`
You need:
SELECT * FROM faq ORDER BY `order`
You're using single-quotes in your example. MySQL uses backticks for wrapping table names, field names, etc. You need to use backticks in this case because order is a reserved word in MySQL.
You're quoting 'order' like a string, so the sorting will be done by the value order itself (a string) rather than by the column. Change them to backticks instead.
You should use backtik not quotes:
SELECT * FROM faq ORDER BY `order`;
Refer: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

MySQL Regexp search keyword

I use this query
SELECT keyword
FROM files
UNION SELECT keyword
FROM search
WHERE keyword
REGEXP "/(honda)|(jazz)|(manual)/"
AND keyword != "honda jazz manual"
ORDER BY keyword ASC
LIMIT 0 , 10
but I got this result
Big bang theory reference
I want to asking you guys, how to use regexp to search keyword.
Please try the following:
SELECT keyword
FROM
(SELECT keyword
FROM files
UNION SELECT keyword
FROM search) allkeywords
WHERE keyword REGEXP '(honda|jazz|manual)'
AND keyword != 'honda jazz manual'
ORDER BY keyword ASC
LIMIT 0 , 10
See http://sqlfiddle.com/#!2/9341ff/5
Explanation:
(1) The unioned query needed making into a subquery to allow the WHERE clause to affect all of it.
(2) The REGEXP syntax was slightly wrong - parentheses round the whole OR'd expression, not individual items.