I’m trying to find out if a row exists in a table. Using MySQL, is it better to do a query like this: SELECT COUNT(*) AS total FROM table1 WHERE … and check to see if the total is non-zero or is …
I’m trying to replace a bunch of characters in a MySQL field. I know the REPLACE function but that only replaces one string at a time. I can’t see any appropriate functions in the manual. Can I replace or delete multiple strings at once? For example I need to replace spaces with dashes and remove other punctuation. Answer You can
I want to show the closest related item for a product. So say I am showing a product and the style number is SG-sfs35s. Is there a way to select whatever product’s style number is closest to that? …
I want to do something like : maxof(Null,1000) should be 1000, How to implement the maxof? Answer If you know that salaryplus will always be greater than salaryminus, then you can do coalesce will return the first value which is not null, or (in this example) 0, if both values are null. Otherwise, do something like this: This will treat
I have a table emp with following structure and data: When I execute the following SQL: I get the following result: On what basis did the server decide return Jill and Fred and exclude Jack and Tom? I am running this query in MySQL. Note 1: I know the query doesn’t make sense on its own. I am trying to
Is there anything returned from MySQL/PHP on a INSERT query being executed? Here is my function which I have in a CLASS. This is how I call the function But executing a INSERT query the $rs returns nothing. Does my function need help or is this the default behavior? Any tips would be helpful as well. Answer INSERT just returns
I’m trying to fetch some data from a database. I want to select an employee, and if available, all appointments and other data related to that employee. This is the query: SELECT TA.id, TEI….
I have a Jobs and a Companies table, and I want to extract 20 jobs that meet the following criteria: Jobs only from two (2) named companies There can at most be 10 jobs per company I have tried the following SELECT with UNION DISTINCT, but the problem is that the LIMIT 0,10 applies to the whole result set. I
I am using MySQL, I have a table that has 9 columns. One of them is the primary key. How can I select a single row, by the primary key or column 8 or 4? Answer If I understand your question correctly: The ‘LIMIT’ keyword makes sure there is only one row returned.
I keep getting MySQL error #1054, when trying to perform this update query: It’s probably some syntax error, but I’ve tried using an inner join instead and other alterations, but I keep getting the same message: Answer Try using different quotes for “y” as the identifier quote character is the backtick (`). Otherwise MySQL “thinks” that you point to a