mysql

Find most occurring records. RoR

suppose there are 3 fields in a mysql table. id, word and date. the word field is not a unique field, so many records have the same word. so how do i find out which word is repeated in records the most? exactly. the most repeated 5 words.. thanks ...

MySQL - Selecting records based on maximum secondary ID

Here's part of my table: id team_id log_id 1 12 1 2 12 1 3 12 1 4 12 1 5 1 2 6 1 2 7 1 3 8 1 3 What query would produce this output (so only the records with the highest log_id values are returned that correspond to ...

Understanding MySQL Connector/J's FLOSS exception

I have to create an application which transfers data from a local workstation into a remote MySQL database. Unfortunatly my boss doesn't want to pay for a commercial license, because it's not a critical application and we wouldn't make any money of it, but still he doesn't want to put the full source under GPL. (Please don't comment on...

Can you create a generic script that is not a stored procedure?

I have some experience with SQL Server 2005 and have written many scripts that just have a BEGIN statement and an END. I could use logic such as loops, cursors, etc. However I can not seem to be able to do this in MySQL without creating a stored procedure. I know that stored procs in MySQL are new and might not be as robust as that of SQ...

MYSQL Insert .. Select - Multiple rows & tables with foreign keys?

I'm using an INSERT .. SELECT to 'duplicate' rows from a table (with a different foreign key). This works fine, however it's inserting multiple rows and I now need to do another INSERT to insert multiple rows that are linked to each individual row in the previous SELECT... does that even make sense? Haha. Basically there's a one to man...

How to start MySQL server on windows xp

Whenever I try to start MySQl by typing: E:\mysql-5.1.39-win32\bin>mysql -u root I'm getting an error: ERROR 2003(HY000): Can't connect to MySQL server on 'localhost' (10061) How can I solve above problem? I just downloaded MySQL and unzipped in E drive, I have not done anything. Do I have to make connection first? if yes, how can I ...

Can I have negative tinyint in SQLite?

Hi, I need to create a table (in SQLite) with a column which contains either "-1" or "+1". To save memory it is better not to use "int" as a type of the column. So, I thought about "smallint" and "tinyint". But smallint is not so small (from -32,768 to 32,767) and tinyint can be only positive (from 0 to 255). Are there any other options ...

refine your search with total amount on each item. PHP WITH MYSQL

How is the best way to do a 'running total' system like the tags search on stackoverflow? If I click on 'php' for example, its show the total amount of items on 'each' other tags, and its very fast. How can I do this in php with mysql? ...

Select Only Max 3 Rows From The Same User - MySQL

Let's say there are two tables: Table "photos" with columns: id, title, path, user_id And table "users" with columns: id username What I want to do is select let's say 30 photos from the "photos" table but with condition that there are at most 3 photos from the same user in the fetched result set. So far I have this query: SELECT...

Need help with a MySQL/PHP query involving date ranges

Essentially I need to retrieve some account information from the dbase table where they have a client of the client that has been passed via GET, and the account placement date (dateplaced) is between the start and end dates passed from calendar fields again via GET. The query below returns no rows. I have verified that the SELECT and F...

Mysql Multiple Concat Inner Join, only give one Name

I have three Tables. table1 = anlass table2 = stammdaten_beziehungen table3 = parameter_zuweisungen_anl It gaves me this ERROR: Subquery returns more than 1 row But what i need, is all 'BeziehKuBez' Comma separated in one column. eg. Beziehname1, Beziehname2, ... If have test it with, CONCAT_WS(',', BeziehKuBez). But give me the ...

using SET datatype in mysql

Is it possible to set a varaible to a query result such as: DECLARE result INT; SET result = (SELECT index FROM table WHERE data = 'xxxx' LIMIT 1); Assuming of course you know that there will only be one result set ...

MySql Count Query

I have this query that I am working on for a one time report. Basically what I am trying to do is find all the records where there are more than two transactions by a single account ID last month. I know it is probably something easy, my mind is just blanking. SELECT streaming_transactions.account_id, streaming_transactions_detail....

where can I find list of countries and states for mysql

I am a php developer, I was searching for countries and states list of world in a mysql data format. Can one help me, where can I find and download it. ...

Using LOCATE string function in stored procedure

Is anyone familiar with using the LOCATE with a passed in string varialbe? I am trying to use it to determine if there is a comma in a string that was set in the stored procedure but have not been able to get it to work properly. My code looks something like this DECLARE string VARCHAR(10); DECLARE comma_found INT; SET stri...

Single query for all records having no key in a join table and those having a matching key

I have a trip that has many residencies. I need a single query that returns all trips where no residency information has been specified. And all trips that match a specified residency. I can get the first from this query: SELECT * FROM `trips` WHERE (((NOT EXISTS (SELECT id FROM residencies WHERE trips.id = residencies.trip_id)) Bu...

Run Mysql scripts in a batch?

Can someone link me to a tutorial or explain if there is a way to create some sort of batch file of mysql scripts / stored procs and run them all at the same time? I can not seem to find any documentation on this online but I feel that I might be searching using the wrong terms. ...

MYSQL - SELECT query with LIKE using %% returns incorrect value

Query: SELECT * FROM table WHERE fieldA LIKE '%%' AND fieldB LIKE '%%' AND fieldC LIKE '%%' This returns only records that have all fields completed. My thought would be that it should return all records in the table. Does the '%%' actually represent that a value is needed? UPDATE1: Thanks to some good questions the soluti...

How to get mysql to accept sybase database..table notation

I'm porting a sybase application to mysql and of course there's tons of sql compatibility issues, but one that I don't see an easy way out of without changing every single sql is that in sybase you can refer to a table by db..table notation, but in mysql it requires db.table. I'm kinda on mysql's side on this one, but this is what it is....

How would this lookup table example work?

Say I have a products table that stores off the shelf products that are not customizable and have static pricing. I also have 1 product in this same table that is customizable and it's price and all sorts of characteristics vary based on the configuration. The final price for this customizable product is based on an equation, not a sum...