mysql

what's the best practice to config Hibernate-Spring for multiple database relationship?

We have a main mysql database which all of the applications within our organization need the data within this database. How can I config my java web application to use this database with it's specific database when I use Spring and Hibernate within my application? How can I config JPA annotations for example between CONTRACT table within...

PHP mysql_fetch_array

$n=mysql_num_rows($rs); $i=0; while($n>0) { while(($row=mysql_fetch_array($rs))&&$i<=5) { echo $row['room_name']; $i=$i+1; //echo $n."<br>"; } echo "<br>"; //echo "n1=".$n; $n=$n...

How to select a limited amount of rows for each foreign key?

Hi, I have this table: id feed_id ... Let's say that I have 500 rows and I want to select 3 entries for each feed_id? And 50 as total limit. How to write this SQL? ...

MySQLdb not INSERTING, _mysql does fine.

Okay, I log onto the MySQL command-line client as root. I then open or otherwise run a python app using the MySQLdb module as root. When I check the results using python (IDLE), everything looks fine. When I use the MySQL command-line client, no INSERT has occurred. If I change things around to _mysql instead of MySQLdb, everything works...

Want to calculate the sum of the count rendered by group by option..

i have a table with the columns such id, tid, companyid, ttype etc.. the id may be same for many companyid but unique within the companyid and tid is always unique and i want to calculate the total no of transactions entered in the table, a single transaction may be inserted in more than one row, for example, id tid companyid ttype...

How to select DISTINCT rows without having the ORDER BY field selected

So I have two tables students (PK sID) and mentors (PK pID). This query SELECT s.pID FROM students s JOIN mentors m ON s.pID = m.pID WHERE m.tags LIKE '%a%' ORDER BY s.sID DESC; delivers this result pID ------------- 9 9 3 9 3 9 9 9 10 9 3 10 etc... I am trying to get a list of distinct mentor ID's with this ordering so I am looki...

Mysql Character Mapping

Hi, I would like to map foreign characters, especially Turkish characters, to their Latin-1 equivalent in Mysql. For example, Select name FROM users WHERE id = 1 Result = Çakır but I would like to get it as: Cakir or Özel -> Ozel There are couple of Turkish characters and they all have Latin-1 equivalents. ( http://webdesign.ab...

How to list records for a query and to display 'no records' when no rows returned using a single query?

How to list records for a query and to display 'no records' when no rows returned using a single query? Now i'm using a count(*) query or using the mysql_num_rows and then another query in different result set to list data.. Please tell me whether its possible with a single query..? ...

regular expression or replace function in where clause of a mysql query.

Hi All, I write a mysql query select * from table where name like '%salil%' which works fine but it will no return records with name 'sal-il', 'sa@lil'. So i want a query something like below select * from table whereremove_special_character_from(name)like '%salil%' remove_special_character_from(name) is a mysql method or a regul...

MySQL auto increments disappeared

I have a mysql database with 60 tables most of the tables have primary keys (expect pivot tables) all these primary keys had the attribute AUTO INCREMENT Then over night some how all the primary keys had that attribute removed, and the default value set to 0. I have no idea how this may have been caused. Any suggestions? ...

best mysql field setup to have a "couples" member profile data saving.

Couple database profile entry, which would be the best way to save data. Also the data will be retrieved via php coding and if it could be down with one query code that would be ideal. Within the site_member table create multiple field for each field... ex: m_firstname1, m_firstname2, m_age1, m_age2, etc... Store the couple member data...

How do I write this Django model in SQL?

I want to create a new column. How do I write this in SQL? class mytable(models.Model): created_at = models.DateTimeField(auto_now_add=True) ...

MySQL composite unique on FK's

I want to implement the following constraints in mysql: create table TypeMapping( ... constraint unique(server_id,type_id), constraint foreign key(server_id) references Server(id), constraint foreign key(type_id) references Type(id) ); This throws a 'ERROR 1062 (23000): Duplicate entry '3-4' for key 'server_id'' when...

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I am trying to connect to mysql database using java on windows7. Inspite of adding the complete url of jdbcdriver jar file in CLASSPATH, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver is thrown. Could anyone tell me what i am missing here?? it works if i add the jar file in project library but i want to do it by CLASSPATH itself...

Getting the last 5 records of a joined query

I have a query that does what i want joining table but i need it to change sligtly so i can use it for something else. I need to get the last 5 records so i should be using the max function and limit it to 5 but it's not working properly This is my current query, just need to get the last 5 records (probably by the festivalid) SELECT...

SQL query to retrieve financial year data grouped by the year

Hi, I have a database with lets assume two columns (service_date & invoice_amount). I would like to create an SQL query that would retrieve and group the data for each financial year (July to June). I have two years of data so that is two financial years (i.e. 2 results). I know I can do this manually by creating an SQL query to group...

Is it possible to make changes in mysql's my.ini file using PHP script?

Is it possible to make changes in mysql's my.ini file using PHP script? ...

How to set a filter for an estimated maximum price

I cannot figure out how to set an estimated maximum price for a collection of records. What I want to avoid is to simply use SQL MAX, because maybe there are records with exorbitant prices. For example, in the "computers-hardware" category of OLX (http://www.olx.com/computers-hardware-cat-240) the filter for maximum price is estimately...

Is it possible to apply the Replication mechanism on single MySQL server?

Is it possible to apply the Replication mechanism on single MySQL server? I want to replicate the changes done in test db to Main db in the same server, so can i use this Replication mechanism on same server? ...

Error in connection in ruby.

require 'rubygems' require 'mysql' db = Mysql.connect('localhost', 'root', '', 'mohit') //db.rb:4: undefined method `connect' for Mysql:Class (NoMethodError) //undefined method `real_connect' for Mysql:Class (NoMethodError) db.query("CREATE TABLE people ( id integer primary key, name varchar(50), age integer)") db.query("INSERT INTO peop...