Skip to content

Tag: mysql

Combine Date and Time Fields and Order By DateTime Field

I would like to combine the date and time for meta values performance_date_1 and performance_time_1 and then sort by this new DATETIME value. Here is my SQL query so far, but no luck. Query SQL: SELECT TIMESTAMP(performance_date_1, performance_time_1) as DateTimeTS FROM test ORDER BY DateTimeTS; Because of how the table is structured I am having a hard time accomplishing this.

MYSQL Query select only first record of foreign key

First of all, I am pretty new to MySQL. I am currently stuck with the following query. I have several tables that have relations between each other. Every user can create multiple projects. Every project can have one attachment, multiple attachments (images) or no attachment at all. Every project only has one user. Table users id username avatar 1 user1

mysql error 1822 when trying to create new table with a FOREIGN KEY

trying the following code: Give back Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint ‘stock_ibfk_1’ in the referenced table ‘donation’. Why? how can I solve this problem? Answer to create a foreign key relationship, the parent table column on which you are creating relation must be unique or primary and they must have the

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 MySql service but I don’t see a way to copy a

Array PDO to MYSQL

so i’m trying to get each amenity entered with fav_id but every time i get these two errors i tried with if before foreach() but still get the same two errors i get these two ERRORS Notice: Array to string conversion on line 54 Warning: Invalid argument supplied for foreach() on line 57 Answer This line changes $amenity_name from an

SELECT rows with MAX id minus 1 with group by

I have a table with id, city_id, and stock which looks like this. id city_id stock 1 1 1000 2 2 500 3 3 11000 4 2 600 5 3 12000 6 1 2000 9 3 13000 10 1 3000 11 1 4000 12 2 700 To select the latest stock values for each city_id I used the following query,