Set a column equal to a value in Oracle SELECT - sql

I want to Select a column and set it equal to 0. In SQL I just do this: SELECT Dealer_Fee = 0.
Do I have to use an update? When I try the same thing in Oracle I get "FROM keyword not found where expected."

I am not sure what do you want to do and in which SQL dialect the construction you mentioned works. If you just want to retrieve some value and place it in a named column in Oracle you have to use DUAL table. Try this:
SELECT 0 AS dealer_fee FROM dual;
On the other hand, if you ment T-SQL and placing a value into variable you need to use PL/SQL SELECT INTO clause, like that:
SELECT 0 INTO dealer_fee from dual;
If not try to explain in more detail what are you trying to achieve.

1) In Oracle you must specify FROM clause within SELECT, is not like MS sqlserver where you can omit a FROM clause.
2) If you want to update one specific value, you must use UPDATE clause instead SELECT.
hth

You should use the Update statement. Please visit this oracle reference which explains the Update statement in detail: Update Statement

Take a look at the reference for UPDATE in Oracle:
UPDATE <table_name>
SET <column_name> = <value>

Related

Using UPDATE statement while using multiple WITH

I have a sql statement that returns records that I need and I am using several WITH clauses. I am trying to update one column within the statement.
WITH <name_a> AS (SELECT...),
<name_b> AS (SELECT...using 'name_a'),
<name_c> AS (SELECT...using 'name_b')
SELECT * from <name_c>
How would I write the statement if I just want to update a column in the final <name_c> output? Ex.
UPDATE name_c SET fav_color = 'blue'
for all the records.
I tried just replacing the select with the update statement but I get 'Missing SELECT keyword'.
I found a similar question but it looks like this question focused on updating the value to what was returned from the select statement. Using "WITH" and "UPDATE" statements in the same SQL query

Update field values of table with field values that is in query

UPDATE Tbl, Qry SET Tbl.Submit_Date = [Qry]![FirstOfTIMESTAMP]
WHERE (((Tbl.Info_ID)=[Qry]![INFO_ID]));
I want to update Tbl.Submit_Date with values from [Qry]![FirstOfTIMESTAMP] where both of their info_id are equal.
I get an error saying Operation must have an updateable query. I am using MSAccess. Any help is greatly appreciated.
As you learned, in MS Access queries must be updateable in order to be used in UPDATE queries. As a workaround consider converting your SQL aggregation to domain aggregation with DMin() assuming FirstOfTIMESTAMP is the Min() aggregation from a source table
UPDATE Tbl
SET Tbl.Submit_Date = DMin("TIMESTAMP","SrcTable","Info_ID=" & Tbl.[INFO_ID])

Error show when update using phpmyadmin

When I update a column using phpmyadmin in database with following query
UPDATE members
SET `refered` = (SELECT COUNT (*)
FROM `user_details`
WHERE `user_details.sponser`=`members.username`
)
It show a error message like this
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '*) FROM `user_details` WHERE `user_details.sponser`=`members.username`)' at line 1
What may be reason?
Error is in
COUNT (*)
-----^
Remove the space between COUNT and (*).
Try the below query
UPDATE members SET refered = (SELECT COUNT(*) FROM user_details
WHERE user_details.sponser=members.username)
Does the Select query returns any result. If so what is the result. Looks like all your query is inside '' single quotes that you are using it should be removed. Single quotes need to be removed for example .
UPDATE members
SET refered = (SELECT COUNT (*)
FROM user_details
WHERE user_details.sponser=members.username
)
-- there is not single quotes in the query above. please remove it from yours.
Part of your problem, or maybe the whole problem, is the WHERE clause. You've used backticks for the table name, which is correct (or, at least, it's optional in this case; it's needed if your database name or table name has a MySQL reserved name or is otherwise ambiguous). The problem, though, is that the dot separating the database from the table needs to be outside the backticks. So your WHERE clause should look like this instead:
WHERE `user_details`.`sponser`=`members`.`username`

Use addition in database SQL

Can I use addition in database?
For example: I have data inside database that is integer. It has a value of 5.
Is there a query that will add another 1 to that? So it will become 6.
Please help me I'm a beginner.
This is the most basic form of an update statement:
update the_table
set the_column = the_column + 1
where the_column = 5;
Note that the above will update all rows where the_colum has the value 5. You most probably want to change the where clause to something different, e.g. by selecting only a single row by using a condition on the primary key column(s) of the table.
Check the manual of your DBMS for details, e.g.: http://www.postgresql.org/docs/current/static/dml-update.html

How to write a update SQL using a select SQL

I want to write a update SQL statement, but one conidtion of this statement is the result from a select SQL statement, and I also want to return the result of the select SQL statement.
Like this: update ... set ... where id = (select id from ...)
I want to return the value of id back.
Does anybody know how should I do this?
Thanks in advance!
I don't believe that's possible in one statement. Update then query (select) the new value, or query the value first, and then submit an update.
Alternative would be a stored procedure on the database, which executes the multiple queries and returns the result for you.
This is not possible in all Java database frameworks that I know. Probably you need to separate your query and update in Java.
I don't see any problem in using a subselect in a WHERE clause of an update statement.
For the second request, getting back the value of id, I know this is possible in DB2, and maybe others implement that syntax too:
SELECT id FROM FINAL TABLE (
update ... set ... where id = (select id from ...)
)
This works also for INSERT and DELETE statements. (See the documentation.)
Update statements won't return the updated datasets. The select in that case would be a subselect that isn't directly accessible.
You'd thus have to use at least two queries:
select the ids you want
call the update query passing the previously selected ids as a parameter