Skip to content

Tag: sql

How to count occurrences of a node in SQL XML?

I am trying to do a count on the number of occurrences of the “Colors” node but have been so far unsuccessful. Below is what I have tried so far. If I have the following logic: I get the following error: Msg 2389, Level 16, State 1, Line 50 XQuery [value()]: ‘value()’ requires a single…

Where to place limit clause?

I am trying to place a limit clause on the database query to only show the first 4 results. The current code I am working with is $categories_query = “select c.categories_id, cd.categories_name, …

How to do NULLS LAST in SQLite?

I’d like to sort my result with all NULL columns last (NULLS LAST), as specified in the SQL:2003 extension T611. Sadly, SQLite seems to not support it. Is there a clever workaround?

Inserting NULL into MySQL timestamp

I’m observing unexpected behavior with inserting/updating NULL in a MySQL timestamp column. Consider the following statements. The first insert (when hiredate is not specified in the SQL, hireDate is null(0) which is expected. However when an explicit null passed in SQL, the current date time is inserte…

Return value at max date for a particular id

Here’s my sql server table This seems like it should be easy to do, but I don’t know why I’m stuck. I’d like to select ONLY the max(date) and value at that max(date) for each id. I want to ignore all other dates that aren’t the max(date) with respect to each id. Here’s what…

cannot get simple PostgreSQL insert to work

I’m trying to do a simple insert into a postgres table, but am getting an error that the value I’m trying to insert is being interpreted as a column name Where id is set up to be the primary key, and auto increment, and not null. Those are the boxes I ticked when I set up the table in phpPgAdmin.