Questions tagged [sql]

SQL is known as Structured Query Language and serves as a powerful tool for querying databases. When asking questions about SQL, it is recommended to provide comprehensive information such as code examples, table structure, sample data, and the specific DBMS implementation being used (e.g., MySQL, PostgreSQL, Oracle, MS SQL Server, IBM DB2, etc.). If your question specifically pertains to a certain DBMS with its own unique extensions or features, be sure to include that particular tag. It's crucial to note that answers provided for SQL-related questions should adhere to the ISO/IEC standard SQL.

Looking to find a specific term within a JSON object that contains various fields

{ "TaskType": "kkkk", "Status": "SUCCESS", "jobID": "18056", "DownloadFilePath": "https://abcd", "accountId": "1234", "customerId": &q ...

Using Node.js and Express to create a MySQL API that outputs a JSON array as a string

Currently working on setting up an Express API server to fetch data for a portfolio website. I've configured the MySQL table with a JSON data type for the 'images' column, which is supposed to contain multiple image links for a gallery. However, when retri ...

Remove a particular row from a table with PHP

I have created a visually appealing table to showcase data in the following manner: ID name Delete 1 abc Delete 2 def Delete The coding snippet used for the aforementioned display is as follows: <?php $con=mysqli_connect("abc" ...

Utilizing MS SQL, AJAX, PHP, and JSON to fetch dynamic page content based on dropdown selection

I've hit a roadblock in my project. I'm currently working on an event registration system where a user selects an event from a dropdown menu populated by values and IDs retrieved from a SQL stored procedure (index.php). Upon selecting an event, I ...

Retrieving Data for Specific Key in JSON Object using BigQuery

I am facing a challenge with a string object stored in a table column, having the following structure: [{"__food": "true"},{"item": "1"},{"toppings": "true"},{"__discount_amount": " ...

Retrieve the names from one table by querying another table

I am working with a database that consists of 3 tables: Categories, Subcategories, and Articles. Within my Articles table, I have columns labeled CategoryID and SubcategoryID, both of which are foreign keys referencing the Categories and Subcategories tabl ...

Two database queries housed within a single array

I am currently working with 2 queries that are extracting elements from 2 separate databases. My goal is to combine the results of both queries into a single array. Right now, I have one array return, but I want to merge the data from these 2 queries into ...

Integrating Gatsby.js with my Express server for seamless communication

Currently, I am in the process of developing a basic full-stack application that utilizes Gatsby for the front-end and a simple Express server for the backend. Within my database, there are several users, and my objective is to fetch these users from the b ...

Struggling to create a basic CMS using PHP and MySQL, unable to successfully display the data

My latest project involves creating a basic CMS for a website. This is my first time working with MySQL and one of my early experiences with PHP, so I see it as a learning opportunity. Despite consulting numerous resources, the code I've written only resul ...

Retrieving JSON data with SQL

I'm attempting to extract the JSON message below using SQL: { "document": { "Invoice": { "_NavRecordId": "Purch. Inv. Header: 06IF+230033", "InvoiceNumber": "06 ...

Incorporate a PHP variable named "result" into a MySQL query

Is it feasible to integrate PHP data into a MySQL result? Let me elaborate: Consider two tables, one containing user actions and the other user information. By querying the actions table, I retrieve user IDs and count each one grouped by the user: $ids = ...

The Redis Presto connector encounters key corruption when using the `redis.key-prefix-schema-table=true` setting with JSON data format

I am in the process of setting up Presto and Redis on my local machine using the instructions provided in the Presto-Redis Documentation. Problem Overview: When I set redis.key-prefix-schema-table=true and use the prefix dev:simple_table: for a Redis key ...

Fortified CakePHP: Defeating SQL Injection in Validation

I recently added a plugin called "SQL Inject Me" to my Firefox browser and decided to test it on my Cakephp website. To my surprise, the plugin was able to inject several blank user accounts, some with passwords and some without. This is strange because I ...

SQL Injection - what more could you ask for?

Recently, I discovered an interesting Firefox addon called 'SQL Inject Me'. To satisfy my curiosity, I decided to test it on a simple phonebook intranet site that has an admin account. The test results showed 51 #302 errors, but despite trying them out, I ...

How can one properly escape SQL queries using mysql_real_escape_string?

There are single quotes being used in $bio = "$user->description"; when inserting into the database like this; <? $sql = "insert into yyy (id, twitterid, twitterkullanici, tweetsayisi, takipettigi, takipeden, nerden, bio, profilresmi, ismi) values ...

Managing the initial record in mysql

As I work on a slideshow, my goal is to dynamically change the HTML class attribute from "item" to "item active" when the first record is fetched from the database. For all subsequent records, the class should revert back to just "item." $RelatedTo=1; $ ...

Retrieve data from an array and insert it into a SQL database by matching the array element with

Currently, I am attempting to send a JSON payload to SQL in order to import a specific column. Within the JSON data, there is a segment structured like this: "Custom":[ {"id":100, "value" 8 }, {"id":200, ...

What is the proper way to add a NULL value to a decimal type column in PHP?

I am facing an issue with inserting a NULL value into a column named price, which is of type Decimal. The "price" column is nullable and has a default value of NULL. My goal is to insert NULL only when the "price" input field in an HTML form is left empty ...

Retrieve image from SQL database using the folder name as the reference

Back with another question! I'm struggling to make a download query function properly. The issue is that instead of actually downloading the uploaded file, it just creates a "download.php" file and downloads that to the default folder, without giving ...

Guide: Leveraging the Knex object in a separate file

How can I effectively utilize the knex db object across multiple files? As an illustration In my main index.js file: const app = require("express")(); const cors = require("cors"); const bodyParser = require("body-parser"); const user = require("./route ...

Tips for utilizing a single insert command across various data types

Currently developing a web application for a project and I have a query: I am trying to use the insert command, however, I need to insert different data in two separate tables. One table is for users and another is for scheduling appointments. Do I need ...

Retrieve data from table1 based on the criteria specified in table2

I have a project in mind where users can like each other's photos, and if the feeling is mutual, they become a match. It's similar to the concept of the Tinder app. Currently, I am retrieving one photo using the following query: SELECT id, pict ...

Manipulating text columns in SQL tables using PHP to convert them into clickable URLs

I have a column in my database that stores the top gaining athletes on my fantasy sports website. I want to make each athlete's name a clickable link that directs users to their individual page on our site. Currently, the function in the code is calli ...

Creating an SQL select statement with a three-level expression is a complex task that requires careful planning and

How can I create a SQL select query with 3 levels of expressions and statements? Typically, my website operates on an SQLite database and the search results are displayed using the following SQL query: "SELECT DISTINCT * FROM amz WHERE Title LIKE "$qq% ...

Converting SQL code to SQLAlchemy mappings

I have an unusual query that aims to retrieve all items from a parent table that do not have corresponding matches in its child table. If possible, I would like to convert this into an SQLAlchemy query. However, I am unsure of how to proceed as my experie ...

Combining data from three tables using SQL joins

I currently have 3 tables in my database: user, wink, messages Despite laying out what I need, it seems like nobody is fully grasping the concept. SELECT wink.*, user.id, user.points, user.gender, user.firstname, user.email FROM wink INNER JOIN user O ...

Dealing with unescaped double quotes in values while using JSON_VALUE()

I'm currently facing an issue with a table in my database where the field JSONDetail stores JSON data. The problem arose when we encountered unescaped double quotes within one of the values in this field, likely due to migrating from a system that allowed ...

Tips for fetching data from Sqlite that includes apostrophes

When accessing a Sqlite3 table with Python, everything works smoothly except for a table column that contains an apostrophe in the value (e.g. George's). I have figured out the SQL query "SELECT * FROM table WHERE column1 = '" + value1 + "' and column2 = ...

Improving search performance based on popular content hits

I've been searching high and low for a solution to my issue, but so far, I haven't had any luck. Maybe someone here can help steer me in the right direction. I currently have a website that houses a vast amount of content within a MySQL databas ...

How to add multiple entries using Node.js and Tedious

I am currently working with an array of customer objects that I need to insert into a SQL database. These customer objects are retrieved from the request data. For this task, I am utilizing Tedious for handling the request and Tedious Connectionpool to ma ...

Exploring the Interplay of JSON Objects in SQL Server and C#

After executing the following SQL Server query, I successfully created a JSON object: SELECT Attribute 1, Attribute 2, Attribute 3,... AS Identifier FROM Table_1 tbl1_obj INNER JOIN Table_2 tbl2_obj ON tbl2_obj.Id = tbl1_obj.Id FOR JSON AU ...

Transform tabular information into JSON from Redshift by executing a select query to retrieve the data in JSON form

As an illustration, An example of a table id name 1 abc 2 def I am familiar with using "select * from sample For JSON auto" in SQL Server to retrieve records and output them in JSON format. Is there a similar functionality available in Redshift? Here ...

What is the simplest way to send an AJAX request to run a PHP script?

Hey everyone, I'm facing a specific issue on my website that I haven't been able to solve by searching online. Therefore, I decided to create this question myself. What I'm trying to achieve: When I click a button on my site, it triggers a ...

I am experiencing difficulties trying to retrieve information from a SQL database using PHP

Hey there, I'm currently working with a SQL database that stores property information. I have set up a search button to look for properties based on the propertyLocation field. For example: Property ID 1, 5 Bedroom House, London Property ID 2, 3 Bedroom ...

Count the total sum by date and group them while using PHP

Within my MySQL table, I have the following data: user | open | date --------------------------------- User1 | 1 | 2017-05-19 User2 | 1 | 2017-05-19 User3 | 1 | 2017-05-19 User4 | 1 | 2017-05 ...

Is there a way to define a varying number of OR conditions in a Doctrine SQL Where clause?

Is there a way to dynamically generate a Doctrine ORM query that mimics the following SQL statement, considering that the number of values in the 'OR' clause may vary with each execution? SELECT * FROM table1 WHERE table1.group = 1 OR 2 OR 3 For in ...

Embedded Youtube code saved in database is not displaying on HTML form

My PHP update page allows me to modify a website's database that contains YouTube embed codes. However, when I try to edit the embed code on the update page, only "<iframe width=" displays instead of the complete original code. <html> <? ...

Transferring checkbox selections into a text field

Is there a way to automatically populate the related id/name of multiple check boxes in an un-editable text box or text field? I am expanding and clarifying one of the suggestions... I have several checkboxes that I want to save into the SAME database fi ...

The occurrence of mysql_num_rows is prompting a server-wide malfunction

I am trying to determine if a record exists: $query = "SELECT * FROM `collegeInfo` WHERE `name` = '$name' "; $existed = mysqli_query($con, $query); echo mysql_num_rows($existed); The third line is causing an error: 500 - Internal server erro ...

Unpacking a lengthy array in Psycopg2 for efficient insertion into a column in a Postgres table

I am currently managing a local postgres database. The challenge I am facing involves an array that looks like this: [1,2,3,...2600] Because the array is extremely long, manually typing out each element for insertion is not a practical option. That' ...

Managing Positioning of PHP Print Statement

Recently, I developed a PHP script for my site that facilitates user registration and login specifically for membership purposes. If a user successfully logs in, the script redirects them to a landing page for members. However, if the login fails, the scri ...

The SQL query is not functioning properly on the server

I'm having trouble with this query on the server, but it works fine in Phpmyadmin on my local host : SELECT * FROM op_theme_certification AS t INNER JOIN op_category_module AS c ON t.cat_mod_id = c.cat_mod_id, (SELECT cat_mod_id, MAX(date_expiration) A ...

Encountering a missing file error in Django when attempting to modify a database column

Currently, I am exploring the functionalities of Django. In my models.py file: class I(models.Model): pic = models.FileField(#upload image) class Pl(models.Model): user=models.ForeignKey(User) picture = models.ForeignKey(I) Now, let's ...

Example of locking in Sql Server for beginners

My understanding of SQL's locking mechanism has been challenged recently. I know there are shared and exclusive locks, and that multiple shared locks can be applied to the same data simultaneously. However, I am confused as to why query 1 does not block qu ...

Retrieve numerous rows by utilizing the forthcoming SQL Server TSQL command for extracting data from JSON format

I'm attempting to fetch multiple rows using the SQL Server 2017 TSQL code from a JSON object. DECLARE @json NVARCHAR(MAX); SET @json = N'{ "DateCreated": "2020-08-02T16:04:59.3558001+01:00", "Name": "Bolts", &q ...

Put JSON data into SQL database table

I have the SQL Table 1 shown below: id name gender age country ambition 1 Peter Male 20 Italy Doctor 2 Angeli Female 30 Australia Lawyer I need to insert data into another table using a similar approach. Here is how I want the output in SQL Tabl ...

Comparison between SQL and jQuery regarding String Length Problems

I am facing an issue where the length of a string calculated using Sql Server (LEN) and jQuery ($(this).val().length) is different. The content of the string in question is as follows: 'Project Noida Ka-Rate Gr. Noida Ka AJNARA AMBROSIA-Sec. 118 ...

SQL - generating a fresh query upon page refresh

Wondering if Python Flask can maintain data consistency when creating a table based on MySQL query results without reloading in the browser every time I refresh. Can Flask handle this task efficiently? from flask import Flask, render_template import mysql ...

Execute a SQL query every half minute to retrieve a count, and store the results in a designated file

As I work on creating a website, I have incorporated a database that allows users to input data in the form of votes. To enhance user experience, I want to display a counter in the header showing the total number of votes cast so far. However, considering ...

"Encountered a MySQL error while attempting to perform an update

I have a question: Within my database, there are 2 tables: articles: id useid title users id name surname In my view: Author<select name="author" id="author"> <?php foreach ($users as $u): ?> ...

What is the process for constructing a PostgreSQL JSON query that targets a non-existent property within a JSON

Table A contains a column b which stores data in JSONB format b ------------------ {"c": 1} {"c": 1, "d": 2} How can I create a query to retrieve rows where the key 'd' is missing? SELECT * FROM A WHERE b@>'{"c":1}'; The above query will r ...

Using MySql Distinct with various columns

I am working with a MySQL database table that has 4 columns labeled a, b, c, and d. My goal is to select the unique values from all four of these columns in my table. Below is a sample representation of my table: a b c d -------------------------- 1 ...

Encountering a problem with Oracle 12c when attempting to retrieve a JSON value exceeding 11000 characters using JSON_VALUE

While executing the code below on Oracle 12c : DECLARE l_json clob; l_var varchar2(90); l_query clob; mypath clob; l_path_value varchar2(100); BEGIN SELECT json_column into l_json from my_table; SELECT path_colum ...

Fetching data from MySQL based on the day of the week and specific timezones

I'm currently working on an application that stores doctor appointments on a weekday basis. To manage this, we have a schedule table and a calendar table that stores the dates. Below is a snapshot of the schedule table: https://i.stack.imgur.com/OPRPb ...

When combining data from two tables using SQL, PHP fails to display the merged values on the table

Apologies for the inconvenience, but I am spending too much time on this: My SQL query is returning the table as expected, but unfortunately I can't seem to display the result on the table. This is my SQL code: $ssql = "SELECT * FROM tickets JOIN (SELECT ...

Using TypeORM: Implementing a @JoinTable with three columns

Seeking assistance with TypeORM and the @JoinTable and @RelationId Decorators. Any help answering my question, providing a hint, or ideally solving my issue would be greatly appreciated. I am utilizing NestJS with TypeORM to create a private API for shari ...

Parsing JSON array values with dynamic keys into JSON_TABLE with consistent columns

I am facing a challenge with JSON data being imported into my MariaDB/MYSQL database using Airbyte from an API query. I have been using JSON_TABLE to extract the JSON into columns, which has been working quite well. However, I recently noticed that there i ...

What is the best method for saving this object to an SQL database?

As a newcomer to this game, I am curious to know if it's feasible to store the following object in a single column within an SQL database like postgres: { "foo1": ["bar1", "bar2"], "foo2": ["bar1 ...

What happens to the arrays within my function?

I am working on a controller code: public function getChartData(){ $result["categories"] = array(); $result["series"] = array(); $sales = $this->db->Execute("select id_tenant, nama_kantin, count(id_penjualan) as jumlah_penjualan, s ...

Grab the information swiftly

When running a presto command, I received the following result: a| b| c --+--+------ 1 | 3| 6 2 | 4| 5 I am aware of cursor.fetchall() to retrieve all data and cursor.fetchone() for a single row. Now, I am interested in extracting data from a sp ...

Sequelize - The name 'xxx_idx' for the identifier is too lengthy while trying to establish a one-to-many relationship

I am working with 2 tables, physical-assessment-exercise and physical-assessment-lesson. In the file psysical-assessment-lesson.model.js: const Sequelize = require('sequelize'); const DataTypes = Sequelize.DataTypes; module.exports = function ( ...

The API request is experiencing delays due to the large dataset of 250,000 records

Utilizing API calls to retrieve data for the frontend is essential, but with a database table containing 250,000 rows, efficiency becomes a concern. In my .NET Core application, I implement the following query: IQueryable<Message> query = context.Me ...

Ways to hide this notification when showing the outcome in php

Having successfully connected to sqlserver using ODBC in php, I am able to establish a connection with the database and execute queries. However, the results I receive are not as expected. A notice is being displayed: server connected Notice: Use of un ...

A Guide to Replacing a json Field with Null and Inserting it into a PostgreSQL Database

I have thoroughly examined the available options discussed in this context, but I find that most of them do not adequately address my specific situation. In my scenario, I import this information into a database where the field is designated as SMALLINT. H ...

How to efficiently load and integrate CSV timestamps into MySQL database using LOAD DATA INFILE option

I have a CSV file with timestamps in this specific format: timestamp, day_chan2, day_chan3 01/02/2014 00:00, 9, 2 01/02/2014 00:00, 16, 5 My goal is to import this data into a MySQL database using the LOAD DATA I ...

Can one query be used to retrieve data from five databases simultaneously?

Can a program output results from five different databases that serve as the source of data? Thank you. ...

How to create a condition query in Node.js with PostgreSQL

I am looking to enhance my select query by incorporating filter and search values. Users should have the flexibility to search, filter, or do both simultaneously. Here are some scenarios: Success: Search only. select name, id from master.contact where na ...

Requesting information from a linked table

There are two tables: admin and news The structure is as follows: admin ----- id name news ----- id createBy updateBy Currently, the createBy and updateBy fields store the admin id. I would like to retrieve the admin name of createBy and updateBy. How ...

Exploring CakePHP's search functionality for English language dates

In my cakephp application, there is a database table named users containing user data. Each user record includes the registration date stored in a field called date. I want to perform a find query that retrieves all users who registered last month. Here's ...

The error arises from the automated generation of a table if it does not already exist

Can someone please assist me with this issue I'm encountering? I am attempting to create a table using the provided query, which functions correctly in phpMyAdmin but fails to work within my PHP script. If possible, could you kindly identify any errors in ...

What is the best way to transfer data from an HTML input field to a PHP script?

Within my patient_display.php file, I am calling the patient_history.php script and passing along the P_ID. Here is an outline of my code. patient_display.php: echo '<form name="Patient" action="patient_history_display.php" method="get">'; ...

PHP script using SQL SELECT query to retrieve records with dates greater than a specified value, including dynamic PHP variables

After reading through various threads on this issue, I still haven't found a solution that incorporates php variables. I am trying to retrieve the first 100 new records after a specific date from my database, but I'm struggling to make it work. ...

Obtaining every possible combination from a database table using different values

Assume we have a basic DB-table named tab set up in MySQL with the following structure: CREATE TABLE `tab` ( `id` int(11) NOT NULL AUTO_INCREMENT, `val` int(11) DEFAULT NULL, `altval` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ); The table is then popul ...

Learning how to implement the selection tag to upload data to a SQL database using PHP

As a coding beginner, I've been tackling a project involving data insertion into an SQL server with PHP. My current struggle lies in the process of inserting data and capturing select tag objects as variables. I keep encountering Undefined Index error ...

Calculating total group orders in Woocommerce based on specific date custom fields

I need help summarizing the total revenue for each day within a specific time period (e.g. 2020) by grouping orders based on a custom field called "pickup_date". Instead of showing revenue by individual dates, I would like to display it grouped by the "pic ...