Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm having trouble with copying data from a table with the same structure to another table with the same first column. I have 2 tables. One is STANDARD, the other one is called W2.
I then choose a name, for example Test.
I want to copy the values except for the name from the STANDARD table into the W2 table. So replace those values. As you can see the values of Test are different in the W2 table. I want to replace those values with the values from STANDARD.
STANDARD:
W3:
Can someone please help me out?
Try this
Update w2 set
Maandag = (SELECT Maandag From STANDARD a where w2.id = a.id),
Dinsdag = (SELECT Dinsdag From STANDARD a where w2.id = a.id)
Etc....
Where w2.id = 'test'
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 19 days ago.
Improve this question
How to make data zig zag from a,a,a,b,b,b to a,b,a,b,a,b using php or sort?
because i'm try usort but it can't be done
We can certainly do it in MySQL using sort. Here is one possible way to do it. But do try to get the hang of the row_id user varible trick yourself.
create table test(v char(1));
insert test values('a'),('a'),('a'),('b'),('b'),('b');
select v from
(select v ,#a_id:=#a_id+1 as row_id from test,(select #a_id:=0) t1 where v='a'
union
select v ,#b_id:=#b_id+1 as row_id from test,(select #b_id:=0) t2 where v='b') t
order by row_id,v;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am working for small project, the main idea of the project to display
some tours:
DB - Database consist of 2 table like below
The first table consist of 4 raw:
id , tour_id , tour_name, image
and the second table for each tour details like destination and places
and raw is:
id , tour_id , from , to
The main page is done, I can display information of tour with images and url link to details page like www.domain.com/tours/get_tour?=1
where 1 is the tour_id.
My question is how can I show the information from the second table with respect tour_id?
I am working in PHP and HTML and MYSQL.
You need JOIN function of mysql. The use this type of SQL script with PHP:
$sql="SELECT first.tour_id, first.tour_image, second.tour_id
FROM first
JOIN second ON first.tour_id=second.tour_id;";
$results=$conn-->$sql; //with $conn your connection variable
$get_tour = $result->fetch_assoc();
In this way you can get first.tour_name and second.from/to depending on tour_id
Then run a while to export your datas in PHP.
$get_tour is now populated. To call elements, use
$get_tour['first.tour_id'];
$get_tour['second.from'];
...
Let me know if it works!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How do I write a query that takes a list of group ids (could be 1, could be 10, etc) and gets the users who are not in ANY of those groups?
We are using Doctrine, but we can't even figure out how to do it in raw SQL.
It's okay to have PHP generate part of the query if we need to do multiple joins/conditions etc based on how many ids are provided.
If my general assumptions about your table structure are correct, I believe something like this should work:
SELECT *
FROM users
WHERE user_id NOT IN (
SELECT DISTINCT user_id
FROM user_groups
WHERE group_id IN ([your group list])
);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have these tables, members, my_connections, my_thoughts.
How do I add a "Share with your network" functionality where a member can share their thoughts with people they are connected to in my_connections.
Easy. In the my_thoughts table add another column - shared, which will be a boolean (I use tinyint, 0 or 1). Then, to select all thoughts that have been shared by my friends:
select * from
my_connections c
join my_thoughts t on (c.connection_id=t.my_id)
where
c.my_id=<insert my ID here>
and t.shared=1
That's assuming that table my_connections has the columns my_id and conection_id, and that table my_thoughts has a column my_id.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I made a new question cause I don't understand the other answers.
I want to get clear here.
I have a table named "experiences".
It has THREE FIELDS: id, experience_name, years.
I want to combine the TWO COLUMNS : experience_name and year and name it like.. experience
Then i want to make a new table and name it resume_experiences and put the COLUMNS id and experience
can you guys please help me..
How am i gonna do it?
OUTPUT SHOULD BE:
table name: resume_experiences
fields: ID | EXPERIENCE
Try this:
INSERT INTO resume_experiences
(id, experience)
SELECT id, CONCAT(experience_name, ' ', CONVERT(years,UNSIGNED))
FROM experiences
CREATE TABLE IF NOT EXISTS `resume_experiences `
SELECT `id`, CONCAT(`experience_name`, ' ', `years`) AS `experience`
FROM `experiences`;