I have a MySQL table with two duplicate names, how can I separate the IDs of the duplicate names into a separate column? For example, like this: This is my current SQL statement to retrieve the current results in the first table: There is only one duplicate at most for each name. Thanks Answer If you are sure…
Tag: mysql
INSERT and SELECT on the same table in one SQL statement
I have the following SQL query : MySQL is complaining with the following error: Is there a way to achieve this without spliting the SQL statment into 2 ?! Answer
Is there a way/service to get SQL statements that would input all the values of a database into another when inputting a database? [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed last month. Improve this question I have a local SQL database that I want to move onto google cloud’s…
SQL: Substring until second character starting from right keeping left values
I have this filename AAAA_BBBBB_CC_HDDD_HGGG.csv and I’m trying to keep the values after the second underscore starting from the right. So i want to keep any values just before _HDDD_HGGG.csv This is my code: And this is the returned value: Instead of being AAAA_BBBBB_CC. Does anyone has a clue for this…
Subtract row values of 2 columns within same table in SQL query
I’m trying to subtract the row values of 2 different columns in the same table. Table schema I want to subtract com – refund if support column is not NULL and status = 1 Output should be like as Answer Try this: The ‘as output’ names the column in your result set. The where statement f…
use quotes in sql query node.js
I have my query like so: but when I insert the query into my database (I am storing the query for analytical purposes), it fails because of the quotes. how can I fix this? I tried converting thequery to toString(), but that was a useless attempt. Any other ideas? edit: error i am recieving is: Answer This is …
Convention for IDs of child tables
Every tutorial that I watched implemented child tables with two IDs, one ID for the table itself, and one ID that was just a reference to the parent’s table ID, like so: In my project, I’m doing a discord bot, and the only identifier that I need is the server’s ID. There’s no need for …
Filter table to leave out specific rows
I have the table and now I want to list every ProjectName where there is no specified Leader like this: Right now I only know how to filter all ProjectNames with Leaders, but not the way to filter them the other way! Any help is appreciated 🙂 Answer One way to do it is with aggregation and the condition in
How to get the first row per group?
I have a query like this: The result looks like this: Now I want to get the first row for each category_id. So it must be the biggest num and its business_id. So the expected result would be: How can I do that? Answer if your MySQL version support ROW_NUMBER + window function, you can try to use ROW_NUMBER to
SQL Query: Search Across Multiple Fields in JOINed Tables
SQL Version: MySQL 8.0 or SQL Server SQL Fiddle: https://www.db-fiddle.com/f/wcHeXkcynUiYP3qzryoYJ7/6 I have a table of images and a table of tags that link to those images. I want to be able to pass (2) tags to the query and have it select only the images that match BOTH tags. For example, I want to pass Nov…