802 Posted Topics
Re: You can group all rows by their due date and concatenate the task names using the group_concat function. Along those lines: select (if due_date < now(), 'overdue', if( due_date < date_add(now(), interval 1 day), 'today', due_date)) as "Due date", group_concat(taskName) as "Tasks" from MyTaskTable group by "Due date"; This is … | |
Re: To increase safety, you should also - restrict user access to the database to the IP address of your webserver, so that no intruders from outside can read the database; - store the access data (username, database name, password) in a separate file with a name beginning with a dot … | |
Re: What kind of a setup is this where a user may handle all databases except one? Sound like Bluebeard's Lair. If I ever had this problem I would write a script (on OS level) which processes a list of database names, a username and an exception name as arguments and … | |
Re: You cannot INSERT with a WHERE condition. You can UPDATE or DELETE with a WHERE condition. | |
Re: This is bad table design. veh_status should be a separate table with a 1:n relation between vehicles and veh_status. | |
Re: The problem probably was not a data mismatch but a data type mismatch. InnoDB requires exactly the same data type in relations, so you cannot link an integer(11) to an integer(5) field. | |
Re: In practice, limits are set by the hardware, not the software. If your budget allows for adding new nodes as necessary, mysql in the partitioned version is capable of bookkeeping all particles in the universe. | |
Re: If they have all the same structure just concatenate them into one file and import it. If this is not sufficient, have a look at the LOAD DATA INFILE command and the mysqlimport utility. | |
![]() | |
Re: So what is your problem? Any error messages? Or what? | |
Re: Show the complete CREATE TABLE statement. Make sure that both waiter.id_w and customer_1.id_w have an index. The InnoDB engine needs an index on all fields which are used in a foreign key relation. | |
Re: It all depends. If your app does not store any user input which would be overwritten by the uploads, this might work. Keep in mind, though, that the standard mysqldump program inserts code which disables reference integrity checks (for performance reasons, I assume). And if your database is large, the … | |
Re: Your attempt is definitively flawed. If you implement it like that, a deletion of a post may lead to the deletion of reports on comments with the same id. Another solution might be to combine posts and comments in one table, since they only differ in the reference to a … | |
Re: Show some test data and the unexpected as well as the expected results. | |
Re: Also keep an eye on the new argentine legislation where you are free to choose your gender as you like, and on the european discussion on transgender people. Might be that boolean is not the correct datatype for gender after all. In modern applications I'd recommend at least four choices: … | |
Re: It is not clear what your problem is. Or how you tried to solve it. You can sort and group your table by race and forecast. If that's what you want, try `select * from races order by race, forecast ` If you want an explicit "rank", count the number … | |
Re: The + operator does not concatenate strings. Use Concat() instead. And beware of SQL injection. `$_GET[agent_name]` is likely to get you into trouble | |
Re: The character set is a property of the server, the database, the table and the field - in that order. Each has a default which can be overwritten by the following. You can change it using the `alter table` syntax. Then there is the client and the connection character set … | |
Re: What does EXPLAIN <query> tell you? Also have a look at http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index to get some optimization ideas. | |
Re: From a philosophical point of view you cannot alter anything in a database without altering its information, because structure and data are what database information consists of. Even if you add only a column with no data or an enum value which is never used the semantics of the database … | |
Re: Use the IF or IFNULL function: SELECT mem_id, IFNULL(company, CONCAT(fname, ' ', lname)) as theName, addr1, addr2, city, state, zip, country FROM dc_order WHERE STATUS='W' or SELECT mem_id, IF(length(company) > 0, company, CONCAT(fname, ' ', lname)) as theName, addr1, addr2, city, state, zip, country FROM dc_order WHERE STATUS='W' | |
Re: You don't even need any IF for your condition, because like '%%' matches just all content, so you don't have to test for empty variables: $sql = sprintf( "SELECT * FROM property WHERE id > 0 and city like '%%%s%%' and state like '%%%s%%' and county like '%%%s%%' and status … | |
Re: Probably you forgot to change the delimiter before creating the trigger. DELIMITER // create trigger ins_notification after insert on transaction_detail for each row Begin insert into sell_notifications(user_id, product_id, quantity) values(new.transaction_id , new.product_id, new.quantity); End // DELIMITER ; Though this would be much easier to verify if you showed us the … | |
Re: Your query would be fine if you replace 'day_add' by 'date_date': mysql> create table d (day_date date, price integer, allotment integer); Query OK, 0 rows affected (0.03 sec) mysql> insert into d values -> ('2012-05-20','500','2'), -> ('2012-05-21','500','2'), -> ('2012-05-22','500','2'), -> ('2012-05-23','600','4'), -> ('2012-05-24','600','4'), -> ('2012-05-25','500','7'), -> ('2012-05-26','500','7'), -> ('2012-05-27','700','2'), -> … | |
Re: The location of the database files depends on the `datadir` configuration variable in my.ini (or my.cnf, depending on the installation). This configuration file usually resides in the root directory of your mysql installation. But, as drjohn suggests, better export the whole database. `mysqldump` is a command line utility which comes … | |
Re: Change your code to if (strlen($img1)) $img_list .= "<img src='$img1' width='268' height='269' title='$title' alt='$title'/>"; or better if (file_exists($_SERVER['DOCUMENT_ROOT'] . $img1)) $img_list .= "<img src='$img1' width='268' height='269' title='$title' alt='$title'/>"; | |
Re: The exception is thrown already in the query analysis. Try to EXPLAIN your queries and you will see that the first EXPLAIN has a result while the second one is already rejected without the query being actually executed. So I'm not sure where the short-circuiting occurs - not in the … | |
Re: To retrieve all allowed enum values you have to read the table definition. Use the "show create table" statement and parse it for the enum field definition. | |
Re: What is a mysql file? A script containing mysql statements? Read more about it [here](http://dev.mysql.com/doc/refman/5.0/en/comments.html) | |
![]() | Re: urtrivedi's solution assumes that the (id,domain) tupels are the same in 1X and 2X, i.e. that the IDs for all domains are the same in both tables. Since I do not believe this to be the case and since ID presumably is an auto_increment field, change the above suggestion to: … |
Re: If there is always a second entry with the same 'ver' value as the latest, you might try: select * from tblp where (invoice IS NOT NULL) order by latest desc, ver desc limit 1,1 | |
Re: You could use the concat function: select * from mytable where concat(field1,field2,field3...) like '%searchtext%' This is highly inefficient, but with small databases it works. An alternative is to export (dump) the database to a text file and then search with grep or a text editor. | |
Re: A cleaner table structure would have made this easier. I'd propose to have a separate position table as a n:1 child table of members which records the positions: [CODE]create table positions (mem_id integer not null, position enum(1,2,3,4,5,6,7), foreign key (mem_id) references members (mem_id)); [/CODE]Then you could state your query as: … | |
Re: It all dependes. Does your table has relations to other tables? Is the primary key used as a foreign key elsewhere? Do you have orphaned records in relations? If all this is no problem, the easiest way would be this: Restore the backup table in a backup database (here called … | |
Re: 1) You cannot mix aggregate functions with non-aggregate fields with valid results. If you group by p.field1, what would you expect in result for the tupels (field1, field2) = (1,1), (1,2), (2,1),(2,2) ? Should the query return 1 or 2 as the value for field2? The database cannot decide that. … | |
Re: select b.brand, c.category from (SELECT DISTINCT brand from product) b, (SELECT DISTINCT category from product) c | |
Re: Drop the foreign key relations. Modify all three tables to the same data type. Re-create the foreign key relations. | |
Re: This design is so bad it hurts. Do not copy records from one table to another to change their status. Just add a status column, as cereal suggested. Then your code is flawed. You assign some statement text to the $sql variable, but never excecute the INSERT query. Only the … | |
Re: SELECT in a stored procedure does not display anything. Therefore you cannot use it for debugging. In your 2nd sample you have a type: ANDA instead of AND. campo is not the same variable as @campo. | |
Re: Look for the value of datadir in /etc/mysql/my.cnf or /etc/my.cnf, respectively. Usually it's /var/lib/mysql. Unintall mysql with apt-get. Delete this data directory with all subdirectories. Delete all in /etc/mysql and /etc/my.ini, /etc/my.cnf etc. Re-install mysql. | |
Re: Or make the field an enum type which allows only the predefined values. | |
Re: You will definitively have less problems if all your stuff - database, scripts, html templates etc. - are in utf-8. If this is a hassle with phpMyAdmin, use a fine database editor like Navicat or HeidiSQL. If your site has the proper "encoding" attributes in header and meta taga, then … | |
Re: You can use the primary key in one table as a foreign key in as many tables as you like. You get constraint errors if your data are not consistent - if you insert a foreign key which does not exist as a primary key or if you delete a … | |
Re: There is no right way. A standard method is a mysql script which you feed first into your development database, then, if all is fine, into your production database, and which contains all necessary statements for table creation and the initial population with test data. You should not do that … | |
Re: Aquilax* solution supposes that the entry date cannot be changed manually after inserting the records. If it can, the query should rather read [CODE]SELECT Score FROM scores ORDER BY [B]date[/B] DESC LIMIT 1;[/CODE] | |
Re: Presumably you use InnoDB tables on your localhost and MyISAM tables on the web server. MyISAM does not support foreign keys with cascading updates and deletes, but it accepts the syntax without error messages. |
The End.