Concatenate a string with curdate in mysql - mysql

I have the following query:
INSERT INTO insertlog (Inforamtion) VALUES (
concat("Row Was Inserted",curdate());
MySQL is returning an error, but I cannot figure out why. My google searches do not show examples on how to perform something like this.

use it simpler like that
INSERT INTO insertlog (Inforamtion)
SELECT concat("Row Was Inserted ",curdate()) ;
be sure if your column is Information or Inforamtion
your query also works but you missed ) in the end . here demo with both solutions :
Demo to try here

I think you are missing one closing )
Moreover as Bill pointed, you may have spelled your column name incorrectly - information

Related

Laravel 5.6 - GroupBy is not working

I have tried it in several ways but it doesn't work (seems like ignoring it). So what I tried:
$user->notes()->groupBy('title')->get();
Above way completely ignores groupBy and just returns collection of notes.
Note::where('user_id', $user->id)->groupBy('title')->get();
Exactly same output with this one too.
In my database.php, the database is set to 'strict' => false
I have also tried using raw db query, it returns it in a weird format (returns 1 row for each title when I use groupBy)
DB::table('notes')->where('user_id', $user->id)->groupBy('title')->get();
I have seen many people facing this issue however none of the suggested ways (above) solved the issue.
I can achieve what I want with using collection->each(function ($note) {...} ), however while there is groupBy to make achieve this easily with 1 line, why the heavy work..
Does anyone has any idea why it doesn't work?
you just need to call first the ->get() then the ->groupBy() method.
Thats because in a SQL Query you need to select first the elements, then group.
So your code need to be like:
DB::table('notes')->where('user_id', $user->id)->get()->groupBy('title');
Heres an example of a Group By Query:
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
go with select() and please add your group by field in select
e.g DB::table('notes')->select('title','Other_field')->where('user_id', $user->id)->groupBy('title')->get();

retrieving multiple columns from table using redbeanphp

I have a query which retrieves 3 columns from table which works fine in phpmyadmin
SELECT cab_id,
SUM(IF(rating=1,1,0)) as up,
SUM(IF(rating=0,1,0)) as down
FROM rating WHERE cab_id=101
table->'rating'
Can anyone help me to find how I can get this query worked using redbeanphp ?
I tried ,
R::getRow(),R::getAll(),R::$adapter->getAssoc()
none is working!!!
To check the correctness of code I tried,
SELECT * FROM rating group by cab_id having cab_id=101
and found working.But I need the first query statement to work! Any help ,please?
I got the answer finally, This one works.
$val = R::getAll($query);

SELECT * FROM games WHERE

I am having issues with my MySQL syntax. I would like to run a select query where either one of two options are true. However the following code does not work.
SELECT * FROM games WHERE genre="indie" OR title="indie"
I have been fooling around and look at other threads and have found out how to use OR to check the same column for multiple entries but not a way to check different columns for the same entries. When I do:
SELECT * FROM games WHERE genre="indie"
The query works fine. Any help would be greatly appreciated.
The only way I see this really would't work, is if you've mistyped the name of the column 'title' (if the second query you wrote works)
The assumptions about the case sensitivity are wrong, since the second query returns something, the first should return at least the same rows as the second one
In MySQL " " works just as ' ', so this assuption was wrong too.
If you post more information, it would be easier to help you
Maybe you ignoring the upper/lower case? Also use like
You can use this:
SELECT * FROM games WHERE (LOWER(genre) like 'indie') OR (LOWER(title) like 'indie')

count(*) on mysql giving me value 0

select count(*) FROM antecedente_delito WHERE rut_polichile = NEW.rut_polichile
this statement is giving de value 0, when it should give me 18 :/ ive been trying a lot to find any bug in it.
Here's the working solution that I mocked up using/changing your code in SqlFiddle. http://sqlfiddle.com/#!2/ac2e9/1
To trouble shoot this, I would view your actual values and verify that NEW. is returning what you think it should. Sometimes it may be doing some trims or removal of special characters, especially the _ and % signs are likely to stripped in subprocedures.
I would start with the query:
select top 50 rut_polichile, NEW.rut_plichile FROM antecedente_delito
If the issue is not obvious from that add in a varbinary check:
select top 50 cast( rut_polichile as varbinary), cast(NEW.rut_plichile as varbinary) from antecedente_delito
If the table only has 18 records, then you should be good to go with the above troubleshooting, but if there is more data, I would suggest limiting your results from the above by the rowid or other identifier in a where statement.
It's not the answer, but I hope it helps you find the answer.
The SELECT privilege for the subject table if references to table columns occur via OLD.col_name or NEW.col_name in the trigger definition.
but in your trigger i can't see any trigger definition. so try without NEW.
for more info: http://www.sqlinfo.net/mysqldocs/v51/triggers.html or
http://bugs.mysql.com/bug.php?id=31068

Escaping % sign in subquery

I have a query in mySQL that's meant to return search terms that are used on our site. Yes, this is for a tag cloud, and yes, I know it's a mullet :)
We've got an admin page where administrators can view search terms and choose to exclude them from showing up in the cloud. These words go into the "badWords" table. We've gotten some terms like "foo%2525252525252520bar", and we're having trouble getting those excluded.
In pseudocode, the query to get the search terms for the cloud is:
SELECT * FROM `searchTerms` WHERE `word` NOT IN ( SELECT `word` FROM `badWords` )
This works fine, unless one of the terms returned from the subquery has a % in it. Is there a way to escape the entire subquery? I've tried doing a
replace( SELECT `word` FROM `badWords`, '%', '\%' )
... but that's apparently not syntactically correct.
I can do two queries if need be, but wondered if there's a way to get it done as is.
Thanks!
==============================
UPDATE: closing this for now, as I think the error lies elsewhere. Will report back once I know for sure, but don't want folks wasting time answering the question here if it's not the correct question...
Upvoted both of the replies received so far. Thanks, guys.
==============================
UPDATE 2: sigh Nevermind... can't close it :\
==============================
FINAL UPDATE: Well, looks like escaping the value isn't the problem. The admin page passes the value in the URL before it's added to the badWords table. In passing the value via the URL, it changes. So what's added to badWords is actually "foo%25252525252520bar" (there's one less "25" sequence). If I manually update the value in badWords and add back the missing "25" it works as expected. So no need to replace or escape anything. I just need to fix those URL values properly.
==============================
I don't think the % is your problem here. I think that you're trying to use REPLACE() on the subquery itself (SELECT ...), and not on a column value (word). Try this instead:
SELECT * FROM `searchTerms`
WHERE `word` NOT IN (
SELECT REPLACE(`word`, '%', '\%') AS word FROM `badWords`
);
Good luck!
I'm not very good with MySQL syntax, but SQL Server let's you do it this way:
SELECT * FROM `searchTerms` WHERE `word` NOT IN ( SELECT REPLACE(`word`, '%', '\%') FROM `badWords` )
NOTE: Basically all I did was move your REPLACE over some =) Hope this helps.