mysql: What is the right syntax for NOT LIKE? - syntax

Hi I am trying to show tables with names not like a pattern by mysql is throws an error:
SHOW TABLES NOT LIKE "tree%";
returns:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT LIKE "tree%"' at line 1
What is the right syntax?
Thanks Arman.

You could use the WHERE clause extension, as in:
SHOW TABLES WHERE `Tables_in_<DatabaseName>` NOT LIKE 'tree%';
This is supported on MySQL ≥5.0.
Reference:
12.4.5.39. SHOW TABLES Syntax.
20.28. Extensions to SHOW Statements.

LIKE and NOT LIKE are used with SELECT statements. I don't think this works with the SHOW TABLES command.

According to this feature request, this has been introduced in mySQL 5.0.3. However, people there disagree, and it doesn't work in my 5.1.41 installation, either.
I guess the answer is it's not possible.

Related

column "likes.id" must appear in the GROUP BY clause or be used in an aggregate function

So I am trying to add top posts functionality for my Sinatra project using postgresql with the following statement Like.group(:exercise_id).order('COUNT(exercise_id) DESC').each do |like|
But when I try this I get an error saying column "likes.id" must appear in the GROUP BY clause or be used in an aggregate function
And when I add this
Like.group(:exercise_id, :id).order('COUNT(exercise_id) DESC')
It gives me the whole table when all I want is to group by likes. Is there a workaround for this?
What the error is telling you, is that you're selecting for "likes.id", but there is no single likes.id that the database can give you.
This is because by default when you don't tell Rails what you need, Rails will select EVERYTHING.
Think, do you actually need "likes.id"? Looks to me that you're grouping by exercise_id so what you're trying to get is exercises and their like counts. (correct me if I'm wrong.) You don't actually need specific like id-s.
If that's so, we need to tell rails about our intention.
Like.group(:exercise_id).order('COUNT(exercise_id) DESC').select(:exercise_id)
If you also need the count itself, just add it to the select.
Something else you might want to try is just .count. It's pretty smart and will respect your grouping. See if this helps.
Like.group(:exercise_id).count

ODAC Field 'column_name' not found in query columns without alias or table name

Recently we've upgraded our ODAC(Oracle Data Access Components) to version 10.1.5. We started to notice a weird problem. When you execute a query, without specifying the table's name or alias it results in the following error: "Field column_name not found".
Example of working code:
select principalimagem.data_inicio from geral.principalimagem
Another example of working code:
select p.data_inicio from geral.principalimagem p
If you remove the table name or the "p" alias, it will result in an error, with the exactly message above.
For some of my clients, internally, It does not result in the error, but if I connect remotely(outside from their local network), it does. I already changed the TNSNames.ora alias to be exactly like theirs, but it did no good. Any clue from what I should look for?
Thanks.
Turns out the problem was firewall related. The error was very weird itself, and we had the same error sometimes while writing packages and procedures.
Thanks for the help

SQLITE3 strings in where clauses seem confused

I'm wondering if anyone has any clarification on the difference between the following statements using sqlite3 gem with ruby 1.9.x:
#db.execute("INSERT INTO table(a,b,c) VALUES (?,?,?)",
some_int, other_int, some_string)
and
#db.execute("INSERT INTO table(a,b,c) VALUES (#{some_int},"+
+"#{some_int}, #{some_string})")
My problem is: When I use the first method for insertion, I can't query for the "c" column using the following statement:
SELECT * FROM table WHERE c='some magic value'
I can use this:
"SELECT * FROM table WHERE c=?", "some magic value"
but what I really want to use is
"SELECT * FROM table WHERE c IN ('#{options.join("','")}')"
And this doesn't work with the type of inserts.
Does anyone know what the difference is at the database level that is preventing the IN from working properly?
I figured this out quite a while ago, but forgot to come back and point it out, in case someone finds this question at another time.
The difference turns out to be blobs. Apparently when you use the first form above (the substitution method using (?,?)) SQLite3 uses blogs to enter the data. However, if you construct an ordinary SQL statement, it's inserted as a regular string and the two aren't equivalent.
Insert is not possible to row query but row query used in get data that time this one working.
SQLite in you used in mobile app that time not work bat this row query you write in SQLite Browse in that work

MS Access Expressions in Pass-Through Query to Oracle DB

I am trying to create a Pass-through SQL statement from my MS Access 2003 (Yeah, I know it's oldschool but my hands are tied :/) to an Oracle DB on a Server.
Long story short, the server-table contains freezer models, where each model exists 1 to 5 times with the ID prefixed with a value indicating it's condition. The problem is, that I have to fetch all "versions" of a freezer. In Access I would write something like:
SQL = "SELECT Right(FREEZERS.ID,4) FROM FREEZERS WHERE Right(FREEZERS.ID,4) = '" & myID & "'"
But this triggers an error in my Pass-through query to Oracle. Is it even possible to write expressions like this in a pass-through query?
I am using vba and a QueryDef with a connectstring to the server (which works fine if i strip the Right()-expression), and then open a recordset with the result.
Thanks on beforehand, Viggo
EDIT:
Ah, sorry..
Took one last Googling and the Answer popped up:
Apparently Oracle has a different syntax for some of these functions. In this case I found that Oracle has a SUBSTR-function and a LENGTH-function, fixing my problem..
To others in search: The key is searching for Oracle syntax rather than Pass-through syntax..
Source:
http://peoplesofttipster.com/2008/08/18/substringing-and-oracle-sql-basic-trick/
Hope it can help someone else :)
As described in the above:
In Pass-Through queries the SQL language of the server.. :)

Web Developer/WebMatrix: SQL CE database table error when editing

I have a SQL CE database that has just been created. It has 3 tables in it. One table gets an error when trying to edit data inside Web Developer, but the other two work fine. I have no idea what is wrong.
All works when edited inside WebMatrix.
Error:
Table schema:
I kind of can't believe this, but it looks like a bug in Visual Studio. You're getting the error at character 103 because that's where the 'Cast' column is added to the SQL statement - 'Cast' is a reserved keyword in SQL syntax.
Generally to get around that, you would use the bracket syntax to clarify your intent:
SELECT SKU, Title, Description, OFLC, Collection, Price, Distributor, Format, RunningTime, Discs, [Cast], ImageSmall, ImageMedium, ImageLarge From Titles
But for some reason, VS strips out the brackets! I'll keep looking for an answer to the bug (interesting problem), but in general you want to avoid naming columns reserved keywords :-)
http://msdn.microsoft.com/en-us/library/aa226054(v=SQL.80).aspx
Happy Coding!

Resources