I have a project with various parts.... One of which is the calculate the area of all the polygons on a map. When I run the query "select st_area(nycpp.the_geom) from nycpp;" I get a list of all the areas.
Next, I tried adding the results of the query to the nycpp table with
UPDATE nycpp SET area_sizes = (select st_area(nycpp.the_geom) from nycpp);
but get the error -- "more than one row returned by a subquery used as an expression"
I figured out why am I getting the error... what I can not figure out is how write a script that will update all 12K+ records....
Can someone give an example or a link to info on updating multiple records
The database I'm using is PostGIS
Thanks
Chris
You are making it to complicated. Try:
UPDATE nycpp set area_sizes=ST_Area(the_geom);
Related
I'm using a servlet to make the jdbc connection, write the PreparedStatements and execute ResultSets. I am able to display the data into a webpage just fine, however I also want to be able to count the number of entries. I know there are other ways to count how many rows I have using java code, but I want to use SQL statements and I saw this
SELECT COUNT(*) FROM table_name;
and made a preparedstatement and tried to execute. However, it is not returning the value of the count, I instead get
"com.mysql.jdbc.JDBC42ResultSet#4a9b1e8b" or "com.mysql.jdbc.JDBC42PreparedStatement#4a9b1e8b" (because I tried getting the value of the count using both).
Basically, I am wondering how to get the count value in my html table from the servlet, not the long statements above.
Many thanks, I'm a beginner.
When you execute your SQL query with JDBC, you get a Resultset even when you get only one record with only one field as in your question.
You need to call the getInt or the getLong method of your recordset to get the actual value.
long countValue = rs.getLong(1);
Have a look at Oracle's documentation on JDBC
You can also have a look at this post on SO
I have tried to find this answer, but I can't seem to find what I am needing.
I am trying to select a row from a MySQL database, then update a counter in that row. All of this needs to be done in a view so I can call it like a normal select.
I am working with an RSS feed where I have total access to MySQL,but zero access to the PHP that outputs the call (I didn't built it, but I inherited the problem :/). To make the call work, I pass the table name into the RSS feed, and it pretty much does this:
SELECT * (table name I pass in).
Because I can't access the PHP, I can't add an update statement to mark the record I selected as used. All of this is so I don't display the same record twice until all the records have been selected.
I am hoping to be able to do this all in a view. I would like to be able to select a row that hasn't been selected, then update that with a counter so I don't select it again.
Example:
SELECT title,counter FROM example WHERE counter = 0 UPDATE example SET counter++
Any help would be great!
EDIT: I need to be able to update the same row that I select.
I spent half day trying to figure out why appears an error messagebox
Could not find field 'TransactionTypeID'
in my
database. If you open Form1, then apply any filter on column TransactionTypeID using header (for instance, uncheck Blanks) and then try to open sorting/filtering for second column, appears error message.
Error disappears if I convert combobox to text box or remove from form select table Tenants1. I use Access 2010 32 bit. In this example I simplified tables as much as possible, database created from scratch, data imported, compact/repair doesn't help.
Do you have any ideas?
I found the problem. The built-in datasheet form filtering works in a wrong way if tables joined this way:
SELECT VouchersMain1.VDate, VouchersMain1.TransactionTypeID
FROM Tenant1 INNER JOIN VouchersMain1 ON Tenant1.TenantID = VouchersMain1.TenantID;
If I reverse tables join direction, built-in filtering works fine:
SELECT VouchersMain1.VDate, VouchersMain1.TransactionTypeID
FROM VouchersMain1 INNER JOIN Tenant1 ON VouchersMain1.TenantID = Tenant1.TenantID;
Looks like this is another Access bug.
Also, thanks #Munsterlander, problem disappears if form's recordsource replaced by saved query instead of SELECT
Try referencing your field as Forms!FORMNAME!CONTROLNAME. I assume, based off what you wrote, you are trying to filter a query based on what is selected in the combobox.
Delete the table Tenants1 from your form RecordSource (this table is not necessary and do not exposes fields in the resulting query).
You would also note that your recordsource is set (by Access) ReadOnly (bad design, no join defined). Try to add a couple of Records in the Tenant1 table, say it David and Nathan.
You will find that now your query will output 6 records (and not 2), because the query (with no joins) list one row for all records of table Tenant1 (3) and one row for each record of table VouchersMain1 (2), giving a total of 2*3=6 rows.
I have joined 5 tables and done transformation on these tables. Now I got a single table at the end. Now I want to perform sql query on this single table to filter records. But I don't know how to perform simple sql query on this table. I have attached a snap shot which shows the resulting table. How I get this resulting data set as the source? I want to populate my destination after filter out this data.
I am using SSIS 2008.
Click here to see the Table on which I want to perform a simple sql query
SELECT * FROM `first_table`
where `some_column` =
(
SELECT `*`
FROM second_table
WHERE
`some_column2`='something'
LIMIT 1
)
Try this code This will help. You can even use this to connect all those four tables with each other.
From the image you posted, it looks like you have a set of data in the dataflow you're trying to query against. You need to do one of two things at this point. Either you insert the data into a table in the database and use another data flow to query it, or you use use a conditional split (or multicast and conditional splits) to filter the rows down further from there.
Without more detail about what you're actually trying to accomplish, these are the recommendations I can determine.
You could send the rows into a record set destination, but you aren't able to query it like a regular table and you'd need some C#/VB skills to access it to do more than a FOR EACH loop.
Assuming your sql query that you want to run against the resulting table is simple, you can use a script component task. By simple, I mean, if it is of this nature:
SELECT * FROM T WHERE a = 'zz' and b = 'XX' etc.
However, if your query has self joins, then you would be better of dumping the outcome of joining those 5 tables in to a physical table, and go from there.
It appears that query is going to be real straight-forward; in that case using a script component would be helpful.
A separate question: It's advisable to do the sorting at the database level. You are using 5 sort tasks in your solution. Can you please elucidate the reason?
Lets say I have multiple commands like 5000 which updates some column and row in databse - it is number for example
UPDATE salary SET money=2000000 WHERE person=55;
Is there any way how to update such data without destroying the original value? Lets say the money has already exiting and different value? I have searched google and MySQL manual but I did not find any useful query for this. Is there any way how to update such data without destroying the original value? Thank you.
Your guess was almost perfect.
UPDATE salary SET money=money+2000000 WHERE person=55;