This question already has answers here:
Delete sql rows where IDs do not have a match from another table
(4 answers)
Closed 1 year ago.
I have a MySQL database where i want to clean up a table but i do not know how to compare against other table entrys and hope someone can help.
One table in the database is called "stats". in the table "Stats" there is a row called "Page_title" which holds an ID number. The same ID number should exist in the table "url,id" otherwise that entry from "stats" should be removed, how can this be done?
Please see this image for reference.
You can do this with a sub select:
delete from stats where page_title not in (select id from shorturl)
Related
This question already has answers here:
Prevent duplicate values in database - mysql
(2 answers)
Closed 4 months ago.
Long story short,
I'm trying to create a table, where you can enter a company name. However you cannot enter a company name which contains a string value of a previous entered company name. Is this possible to do with a check constraint?
For example:
My company "CrazyJello" is inserted. Now the following companies that are being entered to MySQL cannot have the string "Crazy" in them.
CREATE table company(
name VARCHAR (100)
CHECK (name != ?????)
No, in sql there is the unique index, but it compares the whole content of the field https://www.mysqltutorial.org/mysql-unique/
This question already has answers here:
MySQL, passing a AUTO_INCREMENT to another table
(2 answers)
Insert ID from one table to another in MySQL php
(1 answer)
Closed 5 years ago.
I have two tables booking and client. Booking table will have client's id. Now I want to ask for booking detail first and then user detail next. The problem for me is when I insert booking detail first then insert user detail next I have to insert user's id in booking table. how is it possible?
note:i have to do in core php.
This question already has answers here:
SQL query return data from multiple tables
(6 answers)
Closed 5 years ago.
Table1
Id, name, addresses
101,raja ,chennai
Table2
Id,group,name
101,a,siva
102,b,selva
I want retrieve data from two tables like
Table2.group=a and two table Id must equal then take address from table1 display
Id, name, Address, group
What have you tried so far? Have you taken a look at some of the resources here?
Since this is the type of pretty straightforward SQL query you're likely to do many times over, it's worth you reading the tutorials and learning it yourself. I'll give you a few pointers to begin:
Your two tables are connected by the Id field (most likely, this is the primary key for one table and the foreign key for another). You'll need to JOIN these two tables using that field.
You'll need to specify a WHERE clause to filter for your condition that Table2.group = a.
The fields you want to display can all be specified using SELECT. If you are selecting data FROM Table 1 and joining to Table 2, you won't need to specify the table name before the field name.
This question already has an answer here:
many to many relationship bridge table dilemma
(1 answer)
Closed 8 years ago.
I've a bridge table, says it's table B which contains 2 columns and they are FK of 2 columns of table A and C. It make sense the FK can't be edit since they are references of other PK columns.
What if I've 3 column in table B? It seem like the entire table can't be edit..
I got this notification :
This table does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available.
What is the reason your table would occur from FKs? That is against the normalization rules and you should not really have all of your columns as FKs. The FKs are used to identify the other elements of the row that are not suppose to be FKs.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Remove Duplicate Rows Leaving Oldest Row Only?
MySQL remove duplicate rows
Say that I have the following table coolumns: int logicalid(pk) ,int home, int person say the I have the following records...
1,5,6
2,5,6
3,5,5
4,5,5
After my query, I want to place into the new table only one row with the same home,person column values so this will be the output result:
1,5,6
2,5,5
Any ideas??
Create your new table with an auto-increment column for the id.
Then insert into the table, using a query such as:
insert into newTable(home, person)
select distinct home, person
from oldTable
INSERT INTO newtable(home, person) SELECT DISTINCT home, person FROM sourcetable