We help IT Professionals succeed at work.
Get Started

mysql select multiple tables

projects
projects asked
on
215 Views
Last Modified: 2015-03-17
This doesn't seem to work. I've tried with, without commas and lots of other things. Just can't seem to find an answer searching the net so am posting.

#!/bin/bash
# user_id should be entered at command line as in $1

mysql -u root -p -D database << EOF


SELECT * FROM table1, table2, table3, table4 WHERE user_id = 8;

EOF

Open in new window


I need to do the following.

bash script one
-Output to a file, including the field names for each table with the records lined up below them.
-Read data inserted into multiple tables by the same user_id.
-Write spacer between each table output, such as 'Table1' so I can see where the tables start/end.
-In one table, read not all of the fields but only some

script two
-A second script which allows me to specify the user_id but to delete all of the data shown in first script

I am looking for examples and solutions even better and can supply what ever missing info there is.

Thanks.
Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 23 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE