Skip to content

Tag: sql

Slow Querying DB

I am currently optimising a system with many connected tables. The part that I am working on right now is displaying table orders. The problem is that in this table there are also many relations (around 10) which I am querying. The problem itself is in querying that many relations. I have been using Eloquent …

How to get data from sub-table?

i have “transaction” table and it has date_of_transaction, transaction_number, item_number columns. it has rows. also i have “item” sub-table. they linked with “item_number”. there are item_name and item_category columns for “item” table. i want to print rows wi…

How to make a composite key out of two foreign keys

I have three tables: In Table 1 primary key is pizza and in Table 2 ingredient. In Table 3, pizza and ingredient are foreign keys, that reference Table 1 and Table 2 respectively, and i want to make them into a composite key. Here’s what i tried: But i’m not sure whether it’s a correct imple…

SQL query to split and keep only the top N values

I have the following table data: I need to create a table with a split items column, but with the limitation to have at most N items per name. E.g. for N = 3 the table should look like this: 
I have the following query that splits items correctly, but doesn’t account for the maximum number N. What shoul…