ms access group by gives strange characters [duplicate] - ms-access

I copied and pasted a new version of the data into my MS Access table and now I'm getting weird characters in my queries. Essentially if I say:
SELECT a, b from table1
everything is fine. If I instead do
SELECT a, b from table1 group by a, b
I get really weird characters as a result. At first I got upside down L's, but now I'm getting Chinese characters. It's weird because other queries in my database use the table and get the desired output. It seems like it's only when I do a group by that I have the problems. Any suggestions? I was ready to roll it out, but now I'm getting these errors!

This is a bug typically met if grouping on a memo field.
There may be several workarounds depending on your needs:
Select
a, Left(b, 255) As b
From
table1
Group By
a, Left(b, 255)
Select
a, Mid(b, 1) As b
From
table1
Group By
a, Mid(b, 1)
Select
a, First(b) As firstb
From
table1
Group By
a
Select
a, DLookUp("b","table1","Id = " & [table1]![Id] & "") AS b
From
table1
Group By
a, DLookUp("b","table1","Id = " & [table1]![Id] & "")

I have just had the same issue in various reports. The problem is indeed the Memo Field.
The solution that worked for me was more straight forward... I had to remove the "Group by" for the Memo field and the problem disapeared.
I realize this might not be an option in every situation, but if it is, this is the easiest solution as it requires no rewrite of the SQL or even any other change in the DB.
I found this solution here: Allen Brown - Grouping by Memo field yields garbage

Here is yet another option, which I just tried successfully. I was updating a query that someone else had created, and the author had included every field in the Group By clause, to return distinct records. I removed the entire Group By clause and inserted DISTINCT right after SELECT. No more Chinese. This may not be possible in some situations, but in this case it was a simple fix.
Also, I would not have thought of this if not for the insights offered above. Thanks everyone!

After five months of no problems, I had this issue today on a group query which included a "Count" field, so the "DISTINCT" technique wouldn't work. What I did was wrap my LongText field around the offending field. In this table, all of the fields are ShortText except for "Description". So the field groups by CSTR([Description]) - and now it works fine! By the way - this came shortly after a MS Office 365 update!

Related

cannot access field on a value with type string_google big query

I faced an error in google big query that I haven't been successful to find a solution for that.
I have two tables, Airnow_dataset.adjustedTime_met_la_wind_letter and Airnow_dataset.station_neighbour, the value of wind_direction column in the former table defines the column name of the latter one.
I used "case" clause to refer to the appropriate columns of another table, but an error comes up whenever I run query
cannot access field pm_station on a value with type string at [3:83]
I would like to mention that the number of rows returned in station_neighbour is one, so it shouldn't be a problem. Also, when I hardcoded s.pm_station value, it works fine. I guess the problem is due to aliasing in the outer query, but I don't know how I can fix it. For your information, I have attached the screenshot of my tables as well as my code.
Any help is greatly appreciated.
This is my query:
SELECT s.pm_station, s.RH, (CASE
WHEN s.wind_direction="W" then (SELECT ss.W FROM
`Airnow_dataset.station_neighbour` ss
WHERE ss.pm_station=s.pm_station )
ELSE "na"
END) as neighbour_wind_direction
FROM `Airnow_dataset.adjustedTime_met_la_wind_letter` s
This is image of schemas:
The problem is that your station_neighbour table has a column named S, so the outer alias for adjustedTime_met_la_wind_letter is shadowed within the CASE WHEN expression. To work around the error, use a different alias, e.g.:
SELECT
wind_letter.pm_station,
wind_letter.RH,
(CASE WHEN wind_letter.wind_direction="W" THEN (
SELECT ss.W FROM
`Airnow_dataset.station_neighbour` ss
WHERE ss.pm_station=wind_letter.pm_station )
ELSE "na" END) as neighbour_wind_direction
FROM `Airnow_dataset.adjustedTime_met_la_wind_letter` wind_letter

MySQL return no results from select * where varchar="" query

I'm having issue with my study project for creating database in MySQL.
I've imported data using LOAD to my created table from a CSV file. Now when I'm executing select * from mytable everything show up perfectly, but when I execute select * from bi_jogging.routes as r where r.Creator_Email="jhenderson7c#bbb.org"
I get nothing.
The email is there, I've tried different syntax options but it seems to be something else, I suspect something with the varchar format, I really have nothing in mind.
For other tables it works fine and others not.
You can try using the query:
select * from bi_jogging.routes as r where r.Creator_Email like "%jhenderson7c#bbb.org%"
If like operator shows the result then there may be white spaces in the email, please double check..
For join try this:
select * from bi_jogging.routes as r join bi_jogging.buddies as b
on b.Email like '%r.Creator_Email%'
I think it should work. Again check with same code.
select * from bi_jogging.routes as r where r.Creator_Email='jhenderson7c#bbb.org'
if [select * from mytable] this works ,then try to copy the email from result and paste it in where clause.
There may be conflicts between quotes.
your table entry contains quotes???
check properly. i think you have quotes in your table entry,so when you try this,
select * from bi_jogging.routes as r where r.Creator_Email like "%jhenderson7c#bbb.org%"
'%' sign matches with any character and you will get the result.
Inside the tablejhenderson7c#bbb.org and "jhenderson7c#bbb.org" are completely different.
I found spaces in the mysql tables after few emails, so I guess that was it. burned 8 hours on this one, thank you all. I could not find the spaces at the end of the mail by looking at it, I had to hit backspace to see that only after two hits the last char is deleted
this helped me : UPDATE bi_jogging.results set Mail_Found = TRIM(Replace(Replace(Replace(Mail_Found,'\t',''),'\n',''),'\r',''));

Exporting phpmyadmin query as csv - problems (not a duplicate)

Before anyone says this is a duplicate, I havent found this case anywhere.
I make my query (a joined query with 4 tables) and then hit EXPORT, but it exports just the table and not the query with the combined info and not just the fields I asked for but ALL the fields of the first table in the query. So basically, the query is ignored at the export stage.
I have loooked into "INTO OUTFILE" however, I do not have the right access to access the file after it is created.
I wonder if "INTO OUTFILE" can save files elsewhere? (remotely, I mean)
I wonder if the amount of results (6200( is straining the server?
My code :
SELECT pname, concat(afname, ' ', alname) as artistname, pubname, pwide, phigh, concat(pubcode,'-',psku) as fullsku, catname, concat('/prints/', pubcode,'-',psku, '.jpg') as imagesource, ptext FROM (prints LEFT JOIN publishers ON (publishers.pubid=prints.ppub) LEFT JOIN artists ON (artistid=partist)) LEFT JOIN cats ON (pcat = catid) WHERE psku <> '' AND phigh > 0 ORDER BY pubname,ltrim(alname),ltrim(afname) LIMIT 6200
I have the same problem, when hitting the "export" button at the bottom of my query results, phpmyadmin exports one of the tables, not the query results. I can't figure why. My workaround is to create a new table, adding
CREATE TABLE xxxx AS
before my select query, and then export this new table.
Since I haven't heard anything, I will post my very lame workaround but at least I got what I wanted.
I did a copy/paste into BBEdit and then tidied up the data with a series of find/replaces.
Not ideal and not the quickest solution, but it worked where nothing else would.

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

mysql group_concat in where

I am having a problem with the following query(if this is a duplicate question then i'm terribly sorry, but i can't seem to find anything yet that can help me):
SELECT d.*, GROUP_CONCAT(g.name ORDER BY g.name SEPARATOR ", ") AS members
FROM table_d AS d LEFT OUTER JOIN table_g AS g ON (d.eventid = g.id)
WHERE members LIKE '%p%';
MySQL apparently can't handle a comparison of GROUP_CONCAT columns in a WHERE clause.
So my question is very simple. Is there a workaround for this, like using sub-query's or something similar? I really need this piece of code to work and there is not really any alternative to use other than handling this in the query itself.
EDIT 1:
I won't show the actual code as this might be confidential, I'll have to check with my peers. Anyway, I just wrote this code to give you an impression of how the statement looks like although I agree with you that it doesn't make a lot of sense. I'm going to check the answers below in a minute, i'll get back to you then. Again thnx for all the help already!
EDIT 2:
Tried using HAVING, but that only works when i'm not using GROUP BY. When I try it, it gives me a syntax error, but when I remove the GROUP BY the query works perfectly. The thing is, i need the GROUP BY otherwise the query would be meaningless to me.
EDIT 3:
Ok, so I made a stupid mistake and put HAVING before GROUP BY, which obviously doesn't work. Thanks for all the help, it works now!
Use HAVING instead of WHERE.
... HAVING members LIKE '%peter%'
WHERE applies the filter before the GROUP_CONCAT is evaluated; HAVING applies it later.
Edit: I find your query a bit confusing. It looks like it's going to get only one row with all of your names in a single string -- unless there's nobody in your database named Peter, it which case the query will return nothing.
Perhaps HAVING isn't really what you need here...
Try
SELECT ...
...
WHERE g.name = 'peter'
instead. Since you're just doing a simple name lookup, there's no need to search the derived field - just match on the underlying original field.
GROUP_CONCAT is an aggregate function. You have to GROUP BY something. If you just want all the rows that have %peter% in them try
SELECT d.*, g.name
FROM table_d AS d
LEFT OUTER JOIN table_g AS g
ON (d.eventid = g.id)
WHERE g.name LIKE '%peter%';