Let’s say we want to insert two users and I want to know the userId of each record I inserted. Example: Db: User.lookup database with these columns: UserId(PK, identity) | Username Setup, insert …
Get count and grouping of foreign key
I have this product_user table which has foreign key product in it. I need to group and count all of the products from that table with the same IDs and get that product name so result of the query …
Creating a view (virtual table) which display colums with particular requirements
So I`m trying to make a statistic view which counts various things like how many users are in table called “PACIENTAS” , how many doctors are in table “GYDYTOJAS” and it works. CREATE OR REPLACE …
SQL multi query
I need some help to do it right in one query (if it possible). (this is a theoretical example and I assume the presence of events in event_name(like registration/action etc) I have 3 colums: From this 3 columns we need to create new table with 4 new columns: Result must be looks like this: What I’ve don…
how to avoid duplicate entries
I created a form on my website where the user can create an account. I save everything into a database connected to a website. This is how I created a table: CREATE TABLE Customer( CID int(9) not …
Creating Postgres View getting ERROR: column “id” specified more than once
SCENARIO: I have this select statement that JOINs a bunch of tables together: I’d like to create a Postgres View. So wrote it out like this: I keep getting this error: ERROR: column “id” specified more than once QUESTIONS: How do I fix this error? I would like to create a view called “…
Incremental invoice number with multiple users
In my app I have users and invoices (amongst other things). I’m not sure what’s the best way to make sure the invoices of every user start with 1 and go up incrementally. For example: User 1 makes …
SQL Query not displaying correctly
I am running a query and the result is not showing correctly, unfortunately, I am not sure what is the problem. Would anyone be kind enough to provide some assistance please? Query; Result: Answer Your problem is that a field that you select is very big, that’s why it’s shown this way. I’d b…
concat only if column value does not contain any specific prefix
I want to add the prefix to column’s data those who not like if the column’s value is 123,OI:909, 456,OI:789 then it updates to OI:123,OI:909, OI:456, OI:789 I tried following SQL Answer You could try this syntax:
Create group column with values based on join [closed]
I have two tables 1) a customer table 2)Account table. I want to see what accounts are primary and which are secondary accounts. In one table I have accountRowId and AccountNumber. In the other …